How do I create a unique ID in Java?

Supertux picture Supertux · Sep 7, 2009 · Viewed 334.7k times · Source

I'm looking for the best way to create a unique ID as a String in Java.

Any guidance appreciated, thanks.

I should mention I'm using Java 5.

Answer

aperkins picture aperkins · Sep 7, 2009

Create a UUID.

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