Home »
Java programming language
Java UUID fromString() Method with Example
UUID Class fromString() method: Here, we are going to learn about the fromString() method of UUID Class with its syntax and example.
Submitted by Preeti Jain, on February 21, 2020
UUID Class fromString() method
- fromString() method is available in java.util package.
- fromString() method is used to return UUID from the given string denoting the name (na).
- fromString() 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.
- fromString() method may throw an exception at the time of creating UUID.
IllegalArgumentException: This exception may throw when the given parameter mismatch string denotation.
Syntax:
public UUID fromString(String na);
Parameter(s):
- String na – represents the string that denotes the UUID name.
Return value:
The return type of the method is UUID, it creates UUID with the given name (na).
Example:
// Java program to demonstrate the example
// of UUID fromString(String na) method of UUID
import java.util.*;
public class FromStringOfUUID {
public static void main(String[] args) {
// Instantiate UUID by using fromString() method
UUID uuid = UUID.fromString("46400000-8cc0-11bd-b43e-10d46e4ef14d");
// Display UUID
System.out.println(" UUID.fromString(): " + uuid);
}
}
Output
UUID.fromString(): 46400000-8cc0-11bd-b43e-10d46e4ef14d