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, int len, char c)
left Pad
if (str.length() >= len)
    return str;
StringBuilder ret = new StringBuilder();
while (ret.length() < len - str.length())
    ret.append(c);
return ret.append(str).toString();
StringleftPad(String str, int length)
Pads a string left with spaces
return (leftPad(str, length, ' '));
StringleftPad(String str, int length, char c)
left Pad
if (str.length() >= length) {
    return str;
StringBuffer buf = new StringBuffer();
for (int i = 0; i < length - str.length(); i++) {
    buf.append(c);
buf.append(str);
...
StringleftPad(String str, int length, char padding)
left Pad
final int paddingLength = length - str.length();
if (paddingLength < 0)
    return str;
final StringBuilder builder = new StringBuilder(length);
while (builder.length() < paddingLength)
    builder.append(padding);
builder.append(str);
return builder.toString();
...
StringleftPad(String str, int maxLength, char placeholder)
left Pad
if (str == null) {
    throw new NullPointerException("str should not be null");
if (maxLength < str.length()) {
    throw new IllegalArgumentException("str length should not be greater than: " + maxLength);
String temp = str;
while (temp.length() < maxLength) {
...
StringleftPad(String str, int num, String padStr)
left Pad
if (num <= 0) {
    return str;
StringBuilder sb = new StringBuilder(str.length() + num);
while (num-- > 0) {
    sb.append(padStr);
sb.append(str);
...
StringleftPad(String str, int pad)
left Pad
if (str == null)
    return null;
if (str.length() >= pad)
    return str;
int len = pad - str.length();
for (int i = 0; i < len; i++)
    str = " " + str;
return str;
...
StringleftPad(String str, int size)
left Pad
return leftPad(str, size, ' ');
StringleftPad(String str, int size)

Left pad a String with spaces (' ').

return leftPad(str, size, ' ');
StringleftPad(String str, int size)
left Pad
return leftPad(str, size, ' ');