Java String Pad Zero zeroPadding(String str, int len)

Here you can find the source of zeroPadding(String str, int len)

Description

Converts the string to "zero-padded" string

License

Open Source License

Parameter

Parameter Description
str string to pad
len desired string length including zeros

Return

zero-padded string

Declaration

public static String zeroPadding(String str, int len) 

Method Source Code

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

public class Main {
    /**/* w w  w . ja  va 2 s . com*/
     * Converts the string to "zero-padded" string 
     * @param str string to pad
     * @param len desired string length including zeros
     * @return zero-padded string
     */
    public static String zeroPadding(String str, int len) {
        StringBuffer buffer = new StringBuffer(str);
        for (int i = 0; i < len - str.length(); i++) {
            buffer.insert(0, '0');
        }
        return buffer.toString();
    }
}

Related

  1. zeropad(String s, int len)
  2. zeroPad(String s, int len)
  3. zeroPad(String s, int length)
  4. zeroPad(String string, int digits)
  5. zeroPadAfterTo(String hex, int i)
  6. zeroPadding(String value, int n)
  7. zeroPadLeft(String s, final int len)
  8. zeropadRight(String s, int len)
  9. zeroPadSSN(String ssn)