Java UUID getMostSignificantBits()方法及实例

来源:这里教程网 时间:2026-02-17 21:16:58 作者:

Java UUID getMostSignificantBits()方法及实例

UUIDs是128位的值。Java中UUID类的getMostSignificantBits()方法被用来获取该UUID最重要的64位。

语法

public long getMostSignificantBits()

参数: 该方法不接受任何参数。

返回值: 该方法返回一个整数值,它是这个128位UUID的最重要的64位。

下面的程序说明了getMostSignificantBits()方法的工作。

程序1 :

// Java code to illustrate// getMostSignificantBits() 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 most significant 64 bit        System.out.println("The most significant 64 bit: "                           + UUID_1                                 .getMostSignificantBits());    }}

输出:

UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66The value is: 5737The most significant 64 bit: 6404303215985955288

程序2

// Java code to illustrate// getMostSignificantBits() 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 most significant 64 bit        System.out.println("The most significant 64 bit: "                           + UUID_1.getMostSignificantBits());    }}

输出:

UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66The value is: 5737The most significant 64 bit: 6404303215985955288

相关推荐