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(int value, int padLen, char padChar)
Returns value argument, left-padded to length padLen argument with the sequence of character in padChar argument.
return lpad(String.valueOf(value), padLen, padChar);
Stringlpad(Object str, int len, String padding)
Lpad.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len - str.toString().length(); i++) {
    sb.append(padding);
sb.append(str);
return sb.toString();
Stringlpad(String base, int len, String pad)
Returns the string str left-padded with the string pad to a length of len characters.
if (len < 0) {
    return null;
} else if (len == 0) {
    return "";
char[] data = new char[len];
char[] baseChars = base.toCharArray();
char[] padChars = pad.toCharArray();
...
Stringlpad(String input, char padding, int length)
Padds the string to the left with the given character for the specified length.
if (input == null) {
    input = new String();
if (input.length() >= length) {
    return input;
} else {
    StringBuffer result = new StringBuffer();
    int numChars = length - input.length();
...
Stringlpad(String input, int length)
Left Pads the input String with spaces to take up a specified length NOTE: The input will be truncated if it exceeds the specified length.
return lpad(input, length, ' ');
Stringlpad(String input, String padChar, int finalLength)
lpad
StringBuffer out = new StringBuffer(input);
int currentLength = out.length();
while (currentLength < finalLength) {
    out.insert(0, padChar.subSequence(0, Math.min(padChar.length(), finalLength - currentLength)));
    currentLength = out.length();
return out.toString();
StringlPad(String input, String replace, int length)
l Pad
String format = "%" + length + "s";
return String.format(format, input).replace(" ", replace);
Stringlpad(String s, char addChar, int length)
lpad
StringBuffer val = new StringBuffer();
int currLength = s.length();
for (int i = currLength; i < length; i++) {
    val.append(addChar);
return val.append(s).toString();
Stringlpad(String s, int len, char ch)
Pads a string to the desired length.
if (s == null || s.length() >= len)
    return s;
StringBuffer buf = new StringBuffer(len);
for (len -= s.length(); len > 0; len--)
    buf.append(ch);
buf.append(s);
return buf.toString();
Stringlpad(String s, int len, String padc)
lpad
int slen = 0;
if (s != null) {
    slen = s.length();
    if (slen >= len) {
        return s;
StringBuilder sb = new StringBuilder(s);
...