Here you can find the source of lpad(int maxDigits, long val)
public static String lpad(int maxDigits, long val)
//package com.java2s; //License from project: LGPL public class Main { public static String lpad(int maxDigits, long val) { int ndigits = ndigits(val); int pad = maxDigits - ndigits; StringBuilder buf = new StringBuilder(); while (pad > 0) { buf.append('0'); pad--;// ww w . j a v a2s .c om } buf.append(val); return buf.toString(); } private static int ndigits(long val) { val = Long.highestOneBit(val); int i = 0; while (val > 0) { i++; val /= 10; } return i; } }