The identifier consists of predefined prefix, specific for ticket type, and a number. The number for every newly created Object is incremented in a sequential order.
Field Mask Example Name [name of object] #XXXXXX Sample #123456 Number SC-XXXXXX SC-123456
How to append first 5 places with 0's like 000001
Asked
Active
Viewed 269 times
0
-
2possible ducplicate http://stackoverflow.com/questions/22416826/sequence-generator-in-java-for-unique-id – Fran Montero Sep 04 '15 at 10:57
-
The real answer is to let the database do it. – user207421 Sep 05 '15 at 00:08
1 Answers
0
Use an AtomicInteger
. It's as simple as this:
AtomicInteger sequentialNumber = new AtomicInteger();
int nextNumber = sequentialNumber.incrementAndGet();
[EDIT]
To prepend with zeros use String.format()
. In your case String.format("%06d", number);
where 0 is the pad character and 6 is the total width.

Keith
- 3,079
- 2
- 17
- 26