As already mentioned, an int value with an initial zero is considered an octal value. If you don't need to have the test as an int, why not make it a string? how
String test= new String("012345");
And if you want to use int for the test, you can not add 0, but just use a number and add 0 during printing.
In case you are interested in how you find how much initial zero should be added, you can do this as follows:
int lengthOfItemID=6; int test=12345; String test1=new String("000000"+test); System.out.println(test1.substring(test1.length()-lengthOfItemID));
Pardon syntax errors were the years I last worked with java.
source share