Using java inbuilt UUID object here we are going to print 5 unique ids. Using this approach it is guaranteed that every time java compiler will print the new and unique id.
Output:
d53abfbd-e92a-4651-91f6-fb134b959c0f
bf2da306-74ef-4657-a27d-47d8b9a8e2b9
2a69cb7b-8df1-47a3-90f2-c0fcf0f4d553
70861ec7-40de-493d-8a71-81856445d2a1
a87d98d4-f1af-472b-94fe-af3af6124902
import java.util.UUID;
public class GenerateId {
public static void main(String[] args) {
for (int i = 0; i < 5; i++){
String generatedID = UUID.randomUUID().toString();
System.out.println(generatedID);
}
}
}
Output:
d53abfbd-e92a-4651-91f6-fb134b959c0f
bf2da306-74ef-4657-a27d-47d8b9a8e2b9
2a69cb7b-8df1-47a3-90f2-c0fcf0f4d553
70861ec7-40de-493d-8a71-81856445d2a1
a87d98d4-f1af-472b-94fe-af3af6124902
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
ReplyDeleteKindly keep blogging. If anyone wants to become a Java developer learn from Java EE Online Training from India.
or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.