Java Utility Library

Java UUID - nameUUIDFromBytes() Method



The java.util.UUID.nameUUIDFromBytes() method is used to retrieve a type 3 (name based) UUID based on the specified byte array.

Syntax

public static UUID nameUUIDFromBytes(byte[] name)

Parameters

name Specify a byte array to be used to construct a UUID.

Return Value

Returns a UUID generated from the specified array.

Exception

NA.

Example:

In the example below, the java.util.UUID.nameUUIDFromBytes() method is used to generate a type 3 (name based) UUID based on the given byte array.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a byte array
    byte Arr[] = {10, 5, 25, -10, -30};

    //creating an UUID from byte array
    UUID uid = UUID.nameUUIDFromBytes(Arr);

    //printing the uuid
    System.out.println("UUID created from Byte Array: \n" + uid);  
  }
}

The output of the above code will be:

UUID created from Byte Array: 
7a8a6d29-ac3f-3b42-b547-a9bf21241cc4

❮ Java.util - UUID