Java UUID.clockSequence() method example

Java UUID.clockSequence() method example

By technicalkeeda, Views 359, Date 21-Feb-2018

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.

tags Java

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

Suggested Posts

Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]