UUID getMostSignificantBits() Method in Java with Examples

The UUIDs are 128-bit values. The getMostSignificantBits() Method of UUID class in Java is used to get the most significant 64 bits of this UUID.

Syntax:

public long getMostSignificantBits()

Parameters: The method does not take any parameters.



Return Value: The method returns an integer value which is the most significant 64 bit of this 128 valued UUID.

Below programs illustrate the working of getMostSignificantBits() method:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

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

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.