Java String Pad Zero zeroPadString(String string, int length)

Here you can find the source of zeroPadString(String string, int length)

Description

zero Pad String

License

Open Source License

Declaration

public static final String zeroPadString(String string, int length) 

Method Source Code

//package com.java2s;

public class Main {
    private static final char[] zeroArray = "0000000000".toCharArray();

    public static final String zeroPadString(String string, int length) {
        if (string == null || string.length() > length) {
            return string;
        }/* w w w  .j av a2s .  c o m*/
        StringBuilder buf = new StringBuilder(length);
        buf.append(zeroArray, 0, length - string.length()).append(string);
        return buf.toString();
    }
}

Related

  1. zeroPadLeft(String s, final int len)
  2. zeropadRight(String s, int len)
  3. zeroPadSSN(String ssn)
  4. zeroPadString(String string, int length)
  5. zeroPadString(String string, int length)