Here you can find the source of zeroPadding(String str, int len)
Parameter | Description |
---|---|
str | string to pad |
len | desired string length including zeros |
public static String zeroPadding(String str, int len)
//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(); } }