Monday, June 15, 2026
HomeLanguagesJavaUUID clockSequence() Method in Java with Examples

UUID clockSequence() Method in Java with Examples

The clockSequence() method of UUID class in Java is generally used to know the clock sequence value associated with this UUID. The clock sequence field of this UUID is used to create the 14-bit clock sequence value.

Syntax:

public int clockSequence()

Parameters: This method does not take any parameter.

Return Value: This method returns a int value which is the clock sequence value associated with this UUID.

Exceptions: The method throws UnsupportedOperationException if this UUID is not a version 1 UUID.

Below programs illustrate the working of clockSequence() method:

Program 1:




// Java code to illustrate clockSequence() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating two UUIDs
        UUID UUID_1
            = UUID
                  .fromString(
                      "58e0a7d7-eebc-11d8-9669-0800200c9a66");
  
        // Displaying the UUID
        System.out.println("UUID: "
                           + UUID_1);
  
        // Displaying the clock sequence value
        System.out.println("The clock sequence value is: "
                           + UUID_1.clockSequence());
    }
}


Output:

UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The clock sequence value is: 5737

Program 2:




// Java code to illustrate clockSequence() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating two UUIDs
        UUID UUID_1
            = UUID
                  .fromString(
                      "5fc03087-d265-11e7-b8c6-83e29cd24f4c");
  
        // Displaying the UUID
        System.out.println("UUID: "
                           + UUID_1);
  
        // Displaying the variant Value
        System.out.println("The clock sequence value is: "
                           + UUID_1.clockSequence());
    }
}


Output:

UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The clock sequence value is: 14534
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS