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

StringleftPad(String str, String character, int size)
left Pad
if (str != null) {
    int delta = size - str.length();
    for (int i = 0; i < delta; i++) {
        str = character + str;
return str;
StringleftPad(String string, char pad, int size)
Return the padded left of a string by padding character.
if (string == null || size < 0) {
    return null;
} else if (string.length() == 0 || size == 0) {
    return "";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size; i++) {
    sb.append(pad);
...
StringleftPad(String string, int length)
left Pad
return leftPad(string, length, ' ');
StringleftPad(String strInput, int intLength)
Pad " " to string left side
return leftPad(strInput, intLength, ' ');
StringleftPad(String targetStr, char appendChar, int length)
left Pad
if (targetStr == null) {
    return null;
int len = targetStr.length();
while (len++ < length) {
    targetStr = appendChar + targetStr;
return targetStr;
...
StringleftPad(String text, int length, char padChar)
left Pad
String text2 = text;
if (text2.length() < length) {
    StringBuffer buf = new StringBuffer(""); 
    for (int i = text2.length(); i < length; i++) {
        buf.append(padChar);
    buf.append(text2);
    text2 = buf.toString();
...
StringleftPad(String text, int size)
Pad some text on the left (i.e., right-align it) until it's a specified width.
int numSpaces = size - text.length();
if (numSpaces <= 0)
    return text;
StringBuffer buf = new StringBuffer(size);
for (int i = 0; i < numSpaces; i++)
    buf.append(' ');
for (int i = numSpaces; i < size; i++)
    buf.append(text.charAt(i - numSpaces));
...
StringleftPad(String toPad, int numPads)
left Pad
return leftPad(toPad, numPads, " ");
StringleftPad(String value, int makeLength, char paddingCharacter)
left Pad
if (makeLength <= 0) {
    throw new IllegalArgumentException("Pad length MUST be over zero");
StringBuffer buffer = new StringBuffer();
buffer.append(buildString(paddingCharacter, makeLength - value.length()));
buffer.append(value);
return buffer.toString();
StringleftPad(String value, int size, String pad)
Adds pad on the left side to complete the size
if (value.length() < size && !pad.isEmpty()) {
    return leftPad(pad.concat(value), size, pad);
return value;