Java UUID getLeastSignificantBits()方法及示例
UUIDs是128位的值。Java中UUID类的getLeastSignificantBits()方法被用来获取该UUID中最不重要的64位。
语法
public long getLeastSignificantBits()
参数: 该方法不接受任何参数。
返回值: 该方法返回一个整数值,即这个128位UUID中最没有意义的64位。
下面的程序说明了getLeastSignificantBits()方法的工作。
程序1 :
// Java code to illustrate
// getLeastSignificantBits() 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 value of UUID
System.out.println("The value is: "
+ UUID_1.clockSequence());
// Getting the least significant 64 bit
System.out.println("The least significant 64 bit: "
+ UUID_1
.getLeastSignificantBits());
}
}
输出:
UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The value is: 5737
The least significant 64 bit: -7608541298835023258
程序2
// Java code to illustrate
// getLeastSignificantBits() 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 value of UUID
System.out.println("The value is: "
+ UUID_1.clockSequence());
// Getting the least significant 64 bit
System.out.println("The least significant 64 bit: "
+ UUID_1.getLeastSignificantBits());
}
}
输出:
UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The value is: 5737
The least significant 64 bit: -7608541298835023258