0

Possible Duplicate:
Generate UUID in Java
Create a GUID in Java

I am using below snippet for generating unique id's

String id = Long.toString(System.nanoTime());

Problem is it generates same id till 1 min.

Is there any other way to generate unique id's?

Community
  • 1
  • 1
happy
  • 2,550
  • 17
  • 64
  • 109
  • You're saying your JRE's `nanoTime` implementation generates the same value for an entire minute?! Is your `currentTimeMillis` equally broken? Still voting to close, but that's pretty messed up. – Dave Newton Jun 21 '12 at 13:15

2 Answers2

5

There is a UUID class on the java.util package.

String id = UUID.randomUUID().toString();

Hope this helps.

2

UUID.randomUUID()

http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html

Frank
  • 1,479
  • 11
  • 15