Say you want the length of an integer to be exactly five digits, you can use the below method:
NumberFormat nf=NumberFormat.getInstance(); // Get Instance of NumberFormatnf.setMinimumIntegerDigits(5); // The minimum Digits required is 5nf.setMaximumIntegerDigits(5); // The maximum Digits required is 5String sb=(nf.format((long)12));System.out.println ( " the result is sb " + sb); // Which prints 00012