Java String Pad Left lpad(String str, int len, char padding)

Here you can find the source of lpad(String str, int len, char padding)

Description

lpad

License

Open Source License

Declaration

public static String lpad(String str, int len, char padding) 

Method Source Code

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

public class Main {
    public static String lpad(String str, int len, char padding) {
        if (len < str.length()) {
            return str.substring(str.length() - len);
        } else {/*w  w  w . ja  v  a  2 s.c  o  m*/
            StringBuffer buf = new StringBuffer(len);
            int gap = len - str.length();

            for (int i = 0; i < gap; i++) {
                buf.insert(i, padding);
            }

            buf.insert(gap, str);

            return buf.toString();
        }
    }
}

Related

  1. lpad(String s, int width)
  2. lpad(String s, String fill, int len)
  3. lpad(String src, int length, char padding)
  4. lpad(String str, char pad, int len)
  5. lPad(String str, int len, char pad)
  6. LPad(String str, int length, String chr)
  7. lPad(String str, int length, String padString)
  8. lpad(String str, int size)
  9. lpad(String str, int totalPadAmount, String padChar)