I have several strings of different length
"2323"
"245"
"353352"
I need to convert them to string of the same size such as:
"0002323"
"0000245"
"0353352"
How can I automatically add the correct number of 0s in front of each string ?
thanks
Use String.format
:
Integer i = Integer.valueOf(src);
String format = "%1$07d";
String result = String.format(format, i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With