Java UUID.fromString(String name) method example

In this tutorial, You will learn how to generate a UUID from the string standard representation. Java UUID.fromString(String name) method returns a UUID with the specified value.

Creates a UUID from the string standard representation as described in the toString() method.

syntax

public static UUID fromString(String name)

Parameters

name - A string that specifies a UUID.

Returns

A UUID with the specified value.

Throws

IllegalArgumentException - If name does not conform to the string representation as described in toString().

Java UUID fromString(String name) example

  • Initialize the String String name = "d605a917-a9d4-44d1-a3ef-60e960a4b9b2";
  • UUID.fromString(name); It creates a UUID from the string standard representation.
  • Print UUID value.
package com.technicalkeeda;

import java.util.UUID;

public class App {

    public static void main(String[] args) {

        String name = "d605a917-a9d4-44d1-a3ef-60e960a4b9b2";
        UUID uuid = UUID.fromString(name);

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

output

UUID value is :- d605a917-a9d4-44d1-a3ef-60e960a4b9b2