Here you can find the source of zeroPrepend(long num, int digits)
private static String zeroPrepend(long num, int digits)
//package com.java2s; public class Main { private static final String BLOCK_OF_ZEROS = "000000"; /**//from ww w . j a va 2s. com * Return the string prepended with 0s. Tested as 10x faster than String.format("%06d", ...); Exposed for testing. */ private static String zeroPrepend(long num, int digits) { final String hash = Long.toString(num); if (hash.length() >= digits) { return hash; } else { final int zeroCount = digits - hash.length(); final StringBuilder buffer = new StringBuilder(digits).append(BLOCK_OF_ZEROS, 0, zeroCount) .append(hash); return buffer.toString(); } } }