Java String Pad Left leftPadWithZeros(String input, int expectedSize)

Here you can find the source of leftPadWithZeros(String input, int expectedSize)

Description

left Pad With Zeros

License

Apache License

Declaration

public static String leftPadWithZeros(String input, int expectedSize) 

Method Source Code

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

public class Main {
    private static final String ZERO = "0";

    public static String leftPadWithZeros(String input, int expectedSize) {
        if (input == null) {
            return leftPadWithZeros("", expectedSize);
        }// ww  w  .  j a  v  a2  s.c o  m

        StringBuilder sb = new StringBuilder(expectedSize);

        for (int i = expectedSize - input.length(); i > 0; i--) {
            sb.append(ZERO);
        }

        sb.append(input);
        return sb.toString();
    }
}

Related

  1. leftPadding(String orgStr, String addStr, int strLength)
  2. leftPadInt(int number, int width)
  3. leftPadMultiline(String input, char padChar, int padWidth)
  4. leftPadString(String str, char pad, int length)
  5. leftPadString(String sValue, int iLength, String sPadString)
  6. leftPadZeros(int value, int digits, StringBuilder sb)
  7. leftZeroPad(String s)
  8. leftZeroPadding(int number, int howManyChar)
  9. lpad(final String input, final String padCode, final int toLength)