Java Integer Pad Zero zeroPad(final int amount, final String in)

Here you can find the source of zeroPad(final int amount, final String in)

Description

Pad a string out (yes I know apache commons can do this but it's used by GWT).

License

Apache License

Parameter

Parameter Description
amount pad size
in string

Return

padded value.

Declaration

public static String zeroPad(final int amount, final String in) 

Method Source Code

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

public class Main {
    /**/*w  w w  .  j a  v  a2s . c o  m*/
     * Pad a string out (yes I know apache commons can do this but it's used by
     * GWT).
     * 
     * @param amount
     *            pad size
     * @param in
     *            string
     * @return padded value.
     */
    public static String zeroPad(final int amount, final String in) {
        final int left = amount - in.length();
        final StringBuilder out = new StringBuilder();
        for (int i = 0; i < left; i++) {
            out.append("0");
        }
        out.append(in);
        return out.toString();
    }
}

Related

  1. zeroPad(final byte[] data, final int blockSize)
  2. zeroPad(final int length, final byte[] bytes)
  3. zeropad(final int num, final int size)
  4. zeroPad(int i, int len)
  5. zeroPad(int n, int base, int width)