Java String Pad Left lpad(String s, int length, char pad)

Here you can find the source of lpad(String s, int length, char pad)

Description

lpad

License

Open Source License

Declaration

private static String lpad(String s, int length, char pad) 

Method Source Code

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

public class Main {
    private static String lpad(String s, int length, char pad) {
        if (s == null || s.length() >= length) {
            return s;

        }//from   w w w . j a v a2s.  c  o  m

        StringBuilder result = new StringBuilder(length);
        int padSize = length - s.length();
        while (padSize > 0) {
            result.append(pad);
            padSize--;
        }
        result.append(s);
        return result.toString();
    }
}

Related

  1. lpad(String input, String padChar, int finalLength)
  2. lPad(String input, String replace, int length)
  3. lpad(String s, char addChar, int length)
  4. lpad(String s, int len, char ch)
  5. lpad(String s, int len, String padc)
  6. lpad(String s, int width)
  7. lpad(String s, String fill, int len)
  8. lpad(String src, int length, char padding)
  9. lpad(String str, char pad, int len)