Java Utility Library

Java UUID - variant() Method



The java.util.UUID.variant() method returns the variant number associated with this UUID. The variant number describes the layout of the UUID. The variant number has the following meaning:

  • 0 Reserved for NCS backward compatibility
  • 2 IETF RFC 4122 (Leach-Salz), used by this class
  • 6 Reserved, Microsoft Corporation backward compatibility
  • 7 Reserved for future definition

Syntax

public int variant()

Parameters

No parameter is required.

Return Value

Returns the variant number of this UUID.

Exception

NA.

Example:

In the example below, the java.util.UUID.variant() method returns the variant 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 variant number of the uuid
    System.out.println("Variant Value: " + uid.variant());  
  }
}

The possible outcome is:

Variant Value: 2

❮ Java.util - UUID