How do I create a unique ID in Java? [duplicate]
问题 This question already has answers here : Create a GUID in Java (6 answers) Closed last year . 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. 回答1: Create a UUID. String uniqueID = UUID.randomUUID().toString(); 回答2: If you want short, human-readable IDs and only need them to be unique per JVM run: private static long idCounter = 0; public static synchronized String createID() { return String.valueOf