Java String Pad Zero zeroPad(String s, int len)

Here you can find the source of zeroPad(String s, int len)

Description

=====================================================================================
This method is used to add padding "0" before a string so that the string has the expected length.

License

Open Source License

Parameter

Parameter Description
s String that need to be padded with zero ahead "0"

Return

A zero "0" padding string

Declaration

public static String zeroPad(String s, int len) 

Method Source Code

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

public class Main {
    /**//from  w w w. j  a  v  a2  s . c o m
     * =====================================================================================<br>
     * This method is used to add padding "0" before a string so that the string has the expected
     * length.
     * 
     * @param s
     *            String that need to be padded with zero ahead "0"
     *            
     * @return A zero "0" padding string
     */
    public static String zeroPad(String s, int len) {
        String result = s;
        for (int i = s.length(); i < len; i++)
            result = "0".concat(result);

        return result;
    }
}

Related

  1. zeroPad(String encodeString, int padding)
  2. zeroPad(String encodeString, int padding)
  3. zeropad(String number, int size)
  4. zeroPad(String s, int fieldLength)
  5. zeropad(String s, int i)
  6. zeropad(String s, int len)
  7. zeropad(String s, int len)
  8. zeroPad(String s, int length)
  9. zeroPad(String string, int digits)