Home » Java programming language

Java UUID nameUUIDFromBytes() Method with Example

UUID Class nameUUIDFromBytes() method: Here, we are going to learn about the nameUUIDFromBytes() method of UUID Class with its syntax and example.
Submitted by Preeti Jain, on February 21, 2020

UUID Class nameUUIDFromBytes() method

  • nameUUIDFromBytes() method is available in java.util package.
  • nameUUIDFromBytes() method is used to get a UUID constructed from the given bytes array (byte[]).
  • nameUUIDFromBytes() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • nameUUIDFromBytes() method does not throw an exception at the time of returning UUID.

Syntax:

    public UUID nameUUIDFromBytes(byte[] na);

Parameter(s):

  • byte[] na – represents an array of byte to be used to generate UUID.

Return value:

The return type of the method is UUID, it returns UUID constructed from the given array.

Example:

// Java program to demonstrate the example 
// of UUID nameUUIDFromBytes(byte[] na)
// method of UUID 

import java.util.*;

public class NameUUIDFromBytes {
    public static void main(String[] args) {
        // Instantiate byte[] array
        byte[] by = {
            1,
            2,
            3,
            4,
            5
        };

        // Here, we are creating an UUID
        // by using nameUUIDFromBytes(by)
        UUID uuid = UUID.nameUUIDFromBytes(by);

        // Display UUID value
        System.out.println("UUID.nameUUIDFromBytes(by): " + uuid);
    }
}

Output

UUID.nameUUIDFromBytes(by): 7cfdd078-89b3-395d-aa55-0914ab35e068


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.