How to Create an Unique ID in Java


In this example we will show how to generate an unique ID in Java.

Source Code

package com.beginner.examples;

import java.util.UUID;

public class GenerateID {

	public static void main(String[] args) {
		
		UUID uniqueID = UUID.randomUUID();
		System.out.println(uniqueID);

	}

}

Output:

2e1dc71c-5774-4e97-ba47-26ae7aa843af

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments