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 str, int totalPadAmount, String padChar)
Pad to the left of a string for totalPadAmount using padChar
String padStr = str;
if (padStr.length() < totalPadAmount) {
    String pad = "";
    for (int i = padStr.length(); i < totalPadAmount; i++) {
        pad = pad + padChar;
    padStr = pad + padStr;
return padStr;
Stringlpad(String str, String chr, int length)

Description:Pad string to the left

String retVal = str;
for (int i = 0; i < length - str.length(); i++)
    retVal = chr + retVal;
return retVal;
StringlPad(String string, char[] padding, int length)
Pads the supplied String with padding chars on the left to the specified length and returns the result as a new String.;
if (string == null || string.length() > length) {
    return string;
StringBuffer buf = new StringBuffer(length);
buf.append(padding, 0, length - string.length()).append(string);
return buf.toString();
StringlPad(String target, String fix, int length)
l Pad
if ((target == null) || (fix == null) || (target.length() >= length))
    return target;
StringBuffer newStr = new StringBuffer();
for (int i = 0; i < length - target.length(); i++) {
    newStr.append(fix);
return newStr.append(target).toString();
StringlPad(String val, int length, String padChar)
l Pad
if (val == null)
    return null;
int len = val.length();
StringBuffer pad = new StringBuffer("");
if (length > len) {
    for (int i = 1; i <= length - len; i++)
        pad.append(padChar);
    return pad.toString() + val;
...
Stringlpadding(String s, int n, String padding)
lpadding
StringBuilder strbuf = new StringBuilder();
for (int i = 0; i < n - s.length(); i++) {
    strbuf.append(padding);
strbuf.append(s);
return strbuf.toString();
StringlpadSapce(final String src, final int length)
lpad Sapce
byte[] sourceArray = nvl(src).getBytes();
byte[] targetArray = new byte[length];
int count;
if (sourceArray.length > length) {
    count = length;
} else {
    count = sourceArray.length;
System.arraycopy(sourceArray, 0, targetArray, length - count, count);
for (int i = 0; i < length - count; i++) {
    targetArray[i] = ' ';
return new String(targetArray);
StringlpadWithCount(String input, String str, int count)
lpad With Count
return doPadWithCount(input, str, count, LEFT);