0

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

Community
  • 1
  • 1
Rahmath
  • 17
  • 1
  • 1
  • 8

1 Answers1

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