How to Generate Unique ID Using Java

 Posted On  | Yashwant Chavan 

Java 5 provides UUID class which simply generates the unique ids. The identifiers generated by UUID are unique identifiers , there is no duplication.

Generate Unique Id (

Refer below code, Which generate UUID key. randomUUID() static method return the UUID key.


import java.util.UUID;

public class GenerateUUID {

    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            UUID uniqueKey = UUID.randomUUID();
            System.out.println("UUID:- " + uniqueKey);



Output will be something like that.

UUID:- 32fd1dc0-bb60-4ca0-97d9-aa2bb7bc1172
UUID:- db5dd179-a962-4b1e-8a2a-118bbcaf0070
UUID:- 33d7b835-3e81-4215-a493-3e085f2af7e0
UUID:- d23041b6-3529-4262-84b9-c12202430f6f
UUID:- 22ca9927-3b4e-4899-9c30-5899dad74822
UUID:- f8eaf80a-42f8-4c0e-9b4d-1fa1285e6c02
UUID:- 709ab019-14b3-4dbb-a1cf-462a1187bbb3
UUID:- 69033871-629b-4f3c-bb0a-03a70dbc81e4
UUID:- 6b1fc2fb-0a58-460b-a765-ec57a35294f0
UUID:- afd3cb6f-94a9-43a6-ae4a-874b88d9f4ca

© 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0742 seconds.