This is a very common scenario in programming when there is a requirement to use some unique random id. This tutorial will help us to generate it in Java. In this post, we will see “how to create a unique random ID using the GUID algorithm?”
Simplest example of generating a unique random id using GUID algorithm in Java...!!! Click To TweetExample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import java.util.UUID; public class GenerateUniqueIDUsingGUID { public static void main(String[] args) { System.out.println("Unique ID : "+generateUniqueID()); } public static String generateUniqueID() { String randomUUID = ""; try { UUID uuid = UUID.randomUUID(); randomUUID = uuid.toString(); } catch (Exception e) { e.printStackTrace(); } return randomUUID; } } |
Output:
1 | Unique ID : 7833b8e9-f536-437d-98a9-e7facc330f8c |
Simplest example of generating a unique random id using GUID algorithm in Java...!!! Click To Tweet
If you like this post, please click like button and share it with others on Twitter. Also, check out my other useful blog posts on Java:
Other Useful References: