How to Generate Unique ID in Java (Integer)?

Sajad Bahmani picture Sajad Bahmani · Feb 1, 2010 · Viewed 101.9k times · Source

How to generate unique ID that is integer in java that not guess next number?

Answer

Simon Nickerson picture Simon Nickerson · Feb 1, 2010

How unique does it need to be?

If it's only unique within a process, then you can use an AtomicInteger and call incrementAndGet() each time you need a new value.