Here you can find the source of zeropad(String s, int i)
public static String zeropad(String s, int i)
//package com.java2s; //License from project: Open Source License public class Main { public static String zeropad(String s, int i) { return padleft(s, i, '0'); }/*from w w w. ja v a2s . co m*/ /** * Pad to the left * * @param s string * @param len desired len * @param c padding char * @return padded string */ public static String padleft(String s, int len, char c) { s = s.trim(); if (s.length() > len) { return s; } final StringBuilder sb = new StringBuilder(len); int fill = len - s.length(); while (fill-- > 0) { sb.append(c); } sb.append(s); return sb.toString(); } }