Java中UUID类的clockSequence()方法通常用于了解与此UUID相关联的时钟序列值。此UUID的时钟序列字段用于创建14位时钟序列值。
用法:
public int clockSequence()
参数:此方法不带任何参数。
返回值:此方法返回一个int值,该值是与此UUID关联的时钟序列值。
异常:如果此UUID不是版本1 UUID,则该方法引发UnsupportedOperationException。
以下示例程序旨在说明clockSequence()方法的用法:
示例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());
}
}
输出:
UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The clock sequence value is: 5737
示例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());
}
}
输出:
UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The clock sequence value is: 14534