天天看點

java get uuid_Java UUID getMostSignificantBits()用法及代碼示例

UUID是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-0800200c9a66

The value is: 5737

The 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-0800200c9a66

The value is: 5737

The most significant 64 bit: 6404303215985955288