Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing integer 1 as a string "00001"

 
divya madala
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Thanks,
Divya
 
Angel Dobbs-Sciortino
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use DecimalFormat. It will insert leading 0's into your String.
DecimalFormat num = new DecimalFormat(�00000�);
num.format(yourNumber);
Angel Dobbs-Sciortino
[ November 05, 2003: Message edited by: Angel Dobbs-Sciortino ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic