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

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

By technicalkeeda, Views 990, Date 21-Feb-2018

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.

tags Java

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

Suggested Posts

Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]