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 base, int length, char pad)
left Pad
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length - base.length(); i++) {
    sb.append(pad);
sb.append(base);
return sb.toString();
StringleftPad(String csIn, int nRequiredLength, char cFill)
left Pad
String csOut = new String();
int nLgStringIn = csIn.length();
int nNbcharToPad = nRequiredLength - nLgStringIn;
if (nNbcharToPad > 0) {
    for (int n = 0; n < nNbcharToPad; n++) {
        csOut = csOut + cFill;
    csOut = csOut + csIn;
...
StringleftPad(String in, char padding, int length)
left Pad
String out = "";
int toPad = length - in.length();
if (toPad < 0) {
    throw new IllegalArgumentException("Input string longer than requested length");
out = getStringRepetition(padding + "", toPad) + in;
return out;
StringleftPad(String input, char padding, int length)
left Pad
if (nullOrEmpty(input))
    input = "";
if (input.length() >= length)
    return input;
String padString = createPad(padding, length - input.length());
return padString.concat(input);
StringleftPad(String input, int length, char pad)
Left pad a string with the specified character, if the string length is less than the specified length.
if (input.length() < length) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0, len = length - input.length(); i < len; i++) {
        sb.append(pad);
    sb.append(input);
    return sb.toString();
return input;
StringleftPad(String inStr, int length, char paddingChar)
Left padding the string with the specified padding character upto the specified length.
if (inStr.length() == length)
    return inStr;
StringBuffer outStr = new StringBuffer();
for (int i = inStr.length(); i < length; i++) {
    outStr.append(paddingChar);
outStr.append(inStr);
return outStr.toString();
...
StringleftPad(String original, int length, char padChar)
Pads the String with the given character until it has the given length.
if (original.length() >= length) {
    return original;
return stringOfChar(padChar, length - original.length()) + original;
StringleftPad(String s, char paddingCharacter, int length)
left Pad
if (s.length() >= length)
    return s;
StringBuffer sb = new StringBuffer();
for (int i = s.length(); i < length; i++) {
    sb.append(paddingCharacter);
sb.append(s);
return sb.toString();
...
StringleftPad(String s, int l)
left pad the string passed to a field the size passed
return blanks(l - s.length()) + s;
StringleftPad(String s, int len, char c)
Returns a string of length len left-padded with characters c.
int slen = s.length();
if (slen >= len)
    return s;
else {
    char[] pad = new char[len - slen];
    for (int i = len - slen - 1; i >= 0; i--)
        pad[i] = c;
    return new String(pad) + s;
...