Java String Pad Left lpad(final String input, final String padCode, final int toLength)

Here you can find the source of lpad(final String input, final String padCode, final int toLength)

Description

lpad

License

Apache License

Declaration

public static final String lpad(final String input, final String padCode, final int toLength) 

Method Source Code

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

public class Main {

    public static final String lpad(final String input, final String padCode, final int toLength) {
        if (input != null && input.length() < toLength) {
            final StringBuffer sb = new StringBuffer(input);
            while (sb.length() < toLength) {
                sb.insert(0, padCode);/*from  ww  w .j a v  a  2 s .c  o m*/
            }
            return sb.toString();
        } else {
            return input;
        }
    }
}

Related

  1. leftPadString(String sValue, int iLength, String sPadString)
  2. leftPadWithZeros(String input, int expectedSize)
  3. leftPadZeros(int value, int digits, StringBuilder sb)
  4. leftZeroPad(String s)
  5. leftZeroPadding(int number, int howManyChar)
  6. lpad(final String s, final String pad, final int size)
  7. lpad(int i, int length, char c)
  8. lpad(int length, long number)
  9. lpad(int maxDigits, long val)