Java Utililty Methods String Pad Left

List of utility methods to do String Pad Left

Description

The list of methods to do String Pad Left are organized into topic(s).

Method

StringleftAlignedPaddedString(String input, int length)
Utility to return a left-aligned version of a string padded to the number of characters specified.
if (length <= 0) {
    return null;
StringBuilder output = new StringBuilder();
char space = ' ';
if (input != null) {
    if (input.length() < length) {
        output.append(input);
...
byte[]leftPad(byte[] data, int size, byte pad)
Pad a byte array with leading bytes.
if (size <= data.length) {
    return data;
byte[] newData = new byte[size];
for (int i = 0; i < size; i++) {
    newData[i] = pad;
for (int i = 0; i < data.length; i++) {
...
StringleftPad(final String input, final int size)
left Pad
int pads = size - input.length();
if (pads <= 0)
    return input;
StringBuilder out = new StringBuilder();
for (int i = pads; i > 0; i--)
    out.append(' ');
return out.append(input).toString();
StringleftPad(final String numStr, final int numDigits)
Left pad given number string with zeros.
StringBuffer buff = new StringBuffer(numStr);
int delta = numDigits - numStr.length();
for (int i = 0; i < delta; i++) {
    buff.insert(0, '0');
return buff.toString();
StringleftPad(final String str, final int size, String padStr)

Left pad a String with a specified String.

Pad to a size of size .

 StringUtils.leftPad(null, *, *)      = null StringUtils.leftPad("", 3, "z")      = "zzz" StringUtils.leftPad("bat", 3, "yz")  = "bat" StringUtils.leftPad("bat", 5, "yz")  = "yzbat" StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat" StringUtils.leftPad("bat", 1, "yz")  = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null)  = "  bat" StringUtils.leftPad("bat", 5, "")    = "  bat" 
if (str == null) {
    return null;
if (isEmpty(padStr)) {
    padStr = " ";
final int padLen = padStr.length();
final int strLen = str.length();
...
StringleftPad(final String value, final int length, final char paddingChar)
left Pad
final StringBuilder sb = new StringBuilder(value);
while (sb.length() < length) {
    sb.insert(0, paddingChar);
return sb.toString();
voidleftPad(long value, char padChar, int maxDigits, StringBuilder buf)
Left-pads values where 0 <= n.
int digits = (value == 0) ? 1 : (int) Math.log10(value) + 1;
for (int i = 0; i < maxDigits - digits; i++) {
    buf.append(padChar);
buf.append(value);
StringleftPad(Object obj, char pad, int len)
left Pad
if (obj == null)
    return null;
String str = obj.toString();
int padLen = len - str.length();
if (padLen <= 0)
    return str;
StringBuilder b = new StringBuilder();
for (int i = 0; i < padLen; i++)
...
StringleftPad(String _str, int _size, char _padChar)
left Pad
if (_str == null) {
    return null;
int pads = _size - _str.length();
if (pads <= 0) {
    return _str; 
return padding(pads, _padChar).concat(_str);
...
StringleftPad(String aStr, int aLen)
Right-justify a String in a field, padding left with blank.
return replicate(' ', aLen - aStr.length()) + aStr;