Java UUID variant()方法及实例
每个UUID都有一个描述该UUID生成过程的变体号码。Java中UUID类的variant()方法通常用于获取与此UUID相关的变体号码。
语法
public int variant()
参数: 该方法不接受任何参数。
返回值: 该方法返回一个int值,即与该UUID相关的变体号码。
以下程序说明了variant()方法的工作。
程序1 :
// Java code to illustrate variant() 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 variant number
System.out.println("The variant number is: "
+ UUID_1.variant());
}
}
输出:
UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The variant number is: 2
程序2
// Java code to illustrate variant() 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 variant number is: "
+ UUID_1.variant());
}
}
输出:
UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The variant number is: 2