I want to generate a sequence number starting from 00000001,00000002....(i need all these zero as well)Please help me..Thanks in advance..
Asked
Active
Viewed 1.8k times
3 Answers
7
You can just generate the sequence numbers as integers and then format them like this:
String.format("%08d", yournumber);
See this question: How can I pad an integers with zeros on the left?
2
You just need to use string formatting to pad numbers with zeros:
for (int i = 1; i < 1000; i++) {
String sequence = String.format("%08d", i);
}

WhiteFang34
- 70,765
- 18
- 106
- 111
2
You can just maintain that variable as an integer and use String.format
to format it.
String s = String.format ("%08d", 42); // gives you "00000042"

paxdiablo
- 854,327
- 234
- 1,573
- 1,953