2

I want to generate a sequence number starting from 00000001,00000002....(i need all these zero as well)Please help me..Thanks in advance..

vignesh
  • 1,529
  • 6
  • 33
  • 58
  • None of the answer are from XSLT, and you've accepted one. Retagging –  Mar 22 '11 at 23:18

3 Answers3

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?

Community
  • 1
  • 1
Kai G
  • 3,221
  • 3
  • 24
  • 30
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
  • 68,826
  • 17
  • 104
  • 110
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
  • 814,905
  • 225
  • 1,535
  • 1,899