Java String Pad Left leftPadString(String str, char pad, int length)

Here you can find the source of leftPadString(String str, char pad, int length)

Description

left Pad String

License

Apache License

Declaration

public static String leftPadString(String str, char pad, int length) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String leftPadString(String str, char pad, int length) {
        if (str.length() >= length)
            return str;
        StringBuffer sb = new StringBuffer();
        while (sb.length() < length - str.length())
            sb.append(pad);/*from  w  ww. j a  va  2 s.com*/
        sb.append(str);
        return sb.toString();
    }
}

Related

  1. leftPadding(final StringBuffer strBuf, final int bufLen, final char fill)
  2. leftPadding(String in, int count, char pad)
  3. leftPadding(String orgStr, String addStr, int strLength)
  4. leftPadInt(int number, int width)
  5. leftPadMultiline(String input, char padChar, int padWidth)
  6. leftPadString(String sValue, int iLength, String sPadString)
  7. leftPadWithZeros(String input, int expectedSize)
  8. leftPadZeros(int value, int digits, StringBuilder sb)
  9. leftZeroPad(String s)