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...!!! Share on XExample
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:
Unique ID : 7833b8e9-f536-437d-98a9-e7facc330f8c
Simplest example of generating a unique random id using GUID algorithm in Java...!!! Share on X
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: