Java UUID.nameUUIDFromBytes(byte[] name) method example

In this tutorial, You will learn how to generate random UUID number based on bytes. Java UUID.nameUUIDFromBytes(byte[] name) method returns a UUID generated from the specified array.

Static factory to retrieve a type 3 (name based) UUID based on the specified byte array.

syntax

public static UUID nameUUIDFromBytes(byte[] name)

Parameters

name - A byte array to be used to construct a UUID.

Returns

A UUID generated from the specified array.

Java UUID nameUUIDFromBytes(byte[] name) example

  • Initialize the byte[] byte[] bytes = { 1, 2, 3 };
  • UUID.nameUUIDFromBytes(bytes); It generates a UUID from the byte array.
  • Print the UUID value.
package com.technicalkeeda;

import java.util.UUID;

public class App {

    public static void main(String[] args) {

        byte[] bytes = {
            1,
            2,
            3
        };

        UUID uuid = UUID.nameUUIDFromBytes(bytes);

        System.out.println("UUID value from bytes :-  " + uuid);
    }
}

output

UUID value from bytes :-  5289df73-7df5-3326-bcdd-22597afb1fac