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

Stringlpad(String s, int length, char pad)
lpad
if (s == null || s.length() >= length) {
    return s;
StringBuilder result = new StringBuilder(length);
int padSize = length - s.length();
while (padSize > 0) {
    result.append(pad);
    padSize--;
...
Stringlpad(String s, int width)
Left pad string with blanks to specified width.
if (s.length() < width) {
    return dupl(' ', width - s.length()) + s;
} else {
    return s;
Stringlpad(String s, String fill, int len)
lpad
if (s == null || fill == null || s.length() >= len || fill.length() == 0) {
    return s;
StringBuffer buf = new StringBuffer(s);
while (buf.length() < len) {
    buf.insert(0, fill);
return buf.substring(buf.length() - len, buf.length());
...
Stringlpad(String src, int length, char padding)
lpad
if (src == null) {
    src = "";
while (src.length() < length) {
    src = padding + src;
return src;
Stringlpad(String str, char pad, int len)
lpad
while (str.length() < len) {
    str = pad + "" + str;
return str;
StringlPad(String str, int len, char pad)
l Pad
return lPad(str, len, pad, false);
Stringlpad(String str, int len, char padding)
lpad
if (len < str.length()) {
    return str.substring(str.length() - len);
} else {
    StringBuffer buf = new StringBuffer(len);
    int gap = len - str.length();
    for (int i = 0; i < gap; i++) {
        buf.insert(i, padding);
    buf.insert(gap, str);
    return buf.toString();
StringLPad(String str, int length, String chr)
L Pad
StringBuilder sb = new StringBuilder(str);
while (sb.length() < length)
    sb.insert(0, chr);
return sb.toString();
StringlPad(String str, int length, String padString)
To pad the given string with a user specified character on the left up to the given length.
int lOriginal = str.length();
int lPadStr = padString.length();
int times2Pad = 0;
int lPadded = 0;
if (lOriginal >= length)
    return str;
StringBuffer sb = new StringBuffer();
String padded;
...
Stringlpad(String str, int size)
lpad
if (str.length() >= size)
    return str;
String pad = "";
int nbBlanks = size - str.length();
for (int i = 0; i < nbBlanks; i++)
    pad += " ";
return pad + str;