It's not a secret anymore!
The moose likes Beginning Java and the fly likes Storing integer 1 as a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Storing integer 1 as a string "00001" " Watch "Storing integer 1 as a string "00001" " New topic

Storing integer 1 as a string "00001"

divya madala
Ranch Hand

Joined: Jan 10, 2001
Posts: 61
Can anybody help me here. I need to keep incrementing the integer in a loop and use the same integer as a string of 5 char.
For example if I am incrementing i from 1 to 20000.
My sequence should be printed as 00001,00002,00003......20000
Angel Dobbs-Sciortino
Ranch Hand

Joined: Sep 10, 2003
Posts: 101
Use DecimalFormat. It will insert leading 0's into your String.
DecimalFormat num = new DecimalFormat(�00000�);
Angel Dobbs-Sciortino
[ November 05, 2003: Message edited by: Angel Dobbs-Sciortino ]
subject: Storing integer 1 as a string "00001"
jQuery in Action, 3rd edition