I am trying to generate unique auto increment id which will started from 0
.
I found something for doing this using below code:
private static final AtomicInteger count = new AtomicInteger(0);
uniqueID = count.incrementAndGet();
I can create auto increment ID by manually :
For example :
int i = 0; // Obviously I will declare this variable as global
++i;
In this way I can manage to do this. But I don't want to do this manually. I am finding some java method which will take of all this stuff.
And I found below code :
private static final AtomicInteger count = new AtomicInteger(0);
uniqueID = count.incrementAndGet();
Now my question is, Is this the right way to generate unique ID? Or, is there any other better solution?