Java String Pad Left leftPad(String string, int length)

Here you can find the source of leftPad(String string, int length)

Description

left Pad

License

Open Source License

Declaration

public static String leftPad(String string, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String leftPad(String string, int length) {
        return leftPad(string, length, ' ');
    }/*from w w w. j  av  a 2 s. c o  m*/

    public static String leftPad(String string, int length, char ch) {
        if (string == null || string.length() >= length)
            return string;
        StringBuffer sb = new StringBuffer(length);
        for (int i = (string.length() - 1); i < length - 1; i++)
            sb.append(ch);
        return sb.append(string).toString();
    }
}

Related

  1. leftPad(String str, int size, String padStr)
  2. leftPad(String str, int width, char c)
  3. leftPad(String str, int width, char padding)
  4. leftPad(String str, String character, int size)
  5. leftPad(String string, char pad, int size)
  6. leftPad(String strInput, int intLength)
  7. leftPad(String targetStr, char appendChar, int length)
  8. leftPad(String text, int length, char padChar)
  9. leftPad(String text, int size)