Java UUID - fromString() Method
The java.util.UUID.fromString() method is used to create a UUID from the string standard representation.
Syntax
public static UUID fromString(String name)
Parameters
name |
Specify a string that specifies a UUID. |
Return Value
Returns a UUID with the specified value.
Exception
Throws IllegalArgumentException, if name does not conform to the string representation.
Example:
In the example below, the java.util.UUID.fromString() method is used to create a UUID from the given string.
import java.util.*; public class MyClass { public static void main(String[] args) { String MyString = "d81e4f2e-cdf2-10e6-529b-7df92533d1cb"; //creating an UUID from a string UUID uid = UUID.fromString(MyString); //printing the uuid System.out.println("UUID is: " + uid); } }
The output of the above code will be:
UUID is: d81e4f2e-cdf2-10e6-529b-7df92533d1cb
❮ Java.util - UUID