Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating sequence number in java

Tags:

java

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

like image 279
vignesh Avatar asked Dec 06 '25 04:12

vignesh


2 Answers

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?

like image 198
Kai G Avatar answered Dec 08 '25 16:12

Kai G


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);
}
like image 25
WhiteFang34 Avatar answered Dec 08 '25 18:12

WhiteFang34



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!