UUID fromString() Method in Java with Examples
Last Updated :
27 Dec, 2018
The fromString() method of UUID class in Java is used for the creation of UUID from the standard string representation of the same.
Syntax:
public static UUID fromString(String UUID_name)
Parameters: The method takes one parameter UUID_name which is the string representation of the UUID.
Return Value: The method returns the actual UUID created from the specified string.
Exception: The method throws IllegalArgumentException if an invalid UUID_name is passed.
Below programs illustrate the working of fromString() method:
Program 1:
import java.util.*;
public class UUID_Demo {
public static void main(String[] args)
{
String UUID_name
= "5fc03087-d265-11e7-b8c6-83e29cd24f4c" ;
System.out.println( "The specified String is: "
+ UUID_name);
UUID UUID_1
= UUID
.fromString(UUID_name);
System.out.println( "The UUID from"
+ " specified String: "
+ UUID_1);
}
}
|
Output:
The specified String is: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The UUID from specified String: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
Program 2:
import java.util.*;
public class UUID_Demo {
public static void main(String[] args)
{
String UUID_name
= "58e0a7d7-eebc-11d8-9669-0800200c9a66" ;
System.out.println( "The specified String is: "
+ UUID_name);
UUID UUID_1
= UUID
.fromString(UUID_name);
System.out.println( "The UUID from"
+ " specified String: "
+ UUID_1);
}
}
|
Output:
The specified String is: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The UUID from specified String: 58e0a7d7-eebc-11d8-9669-0800200c9a66
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...