Java UUID.clockSequence() method example

In this tutorial, You will learn how to get the clock Sequence value of this UUID. Java UUID.clockSequence() method throws UnsupportedOperationException - If this UUID is not a version 1 UUID.

The clock sequence value associated with this UUID. The 14 bit clock sequence value is constructed from the clock sequence field of this UUID. The clock sequence field is used to guarantee temporal uniqueness in a time-based UUID.

syntax

public int clockSequence()

Returns

The clock sequence of this UUID.

Throws

UnsupportedOperationException - If this UUID is not a version 1 UUID.

Java UUID clockSequence() example

  • Initialize the String String name = "6224c18d-d004-11bd-984e-b8d80b2bdff8";
  • UUID.fromString(name); It creates a UUID from the string standard representation.
  • uuid.clockSequence(); It returns the clock sequence value associated with this UUID.
package com.technicalkeeda;

import java.util.UUID;

public class App {

    public static void main(String[] args) {

        String name = "6224c18d-d004-11bd-984e-b8d80b2bdff8";
        UUID uuid = UUID.fromString(name);
        
        System.out.println("Clock Sequence value :-  " + uuid.clockSequence());
    }
}

output

Clock Sequence value :-  6222