Java Utility Library

Java UUID - version() Method



The java.util.UUID.version() method returns the version number associated with this UUID. The version number describes how this UUID was generated. The version number has the following meaning:

  • 1 Time-based UUID
  • 2 DCE security UUID
  • 3 Name-based UUID
  • 4 Randomly generated UUID

Syntax

public int version()

Parameters

No parameter is required.

Return Value

Returns the version number of this UUID.

Exception

NA.

Example:

In the example below, the java.util.UUID.version() method returns the version number of the given UUID.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a random UUID
    UUID uid = UUID.randomUUID();

    //printing the version of the uuid
    System.out.println("Version Value: " + uid.version());  
  }
}

The output of the above code will be:

Version Value: 4

❮ Java.util - UUID