I am wondering if it is possible, using the String.format method in Java, to give an integer preceding zeros?
For example:
1 would become 001 2 would be
If you are using a third party library called apache commons-lang, the following solution can be useful:
Use StringUtils class of apache commons-lang :
StringUtils
int i = 5; StringUtils.leftPad(String.valueOf(i), 3, "0"); // --> "005"
As StringUtils.leftPad() is faster than String.format()
StringUtils.leftPad()
String.format()