- Given an string representing unique identifier.
- We would like to convert string to corresponding universal unique identifier (UUID) or Globally unique identifier (GUID).
- We will use java.util.UUID class to create UUID or GUID from string.
- e.g UUID generateUUID = UUID.fromString(inputUUID)
Program: generate UUID or GUID from String in java
package org.learn.uuid;
import java.util.UUID;
public class GenerateUUIDFromString {
public static void main(String[] args) {
//Given Input UUID string
String inputUUID = "ea33eca1-c704-4062-a111-98f7b323e824";
System.out.printf("1. Given input string of UUID : %s", inputUUID);
//Generate UUID from string uuid
UUID generateUUID = UUID.fromString(inputUUID);
System.out.printf("\n2. Generate UUID from String (UUID) : %s",
generateUUID.toString());
}
}
Output: generate UUID or GUID from String in java
1. Given input string of UUID : ea33eca1-c704-4062-a111-98f7b323e824
2. Generate UUID from String (UUID) : ea33eca1-c704-4062-a111-98f7b323e824