Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to generate the same UUID from a String

Tags:

java

uuid

I am wondering if there is a way to generate the same UUID based on a String. I tried with UUID, it looks like it does not provide this feature.

like image 596
Adam Lee Avatar asked Mar 15 '15 10:03

Adam Lee


People also ask

Can you generate UUID from string?

The fromString() method of UUID class in Java is used for the creation of UUID from the standard string representation of the same. 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.

Can random UUID be duplicate?

From the documentation and wikipedia we see that randomUUID is good - but there is a very small chance that duplicates can be generated.

Is UUID reversible?

This also means that one can (in theory) guarantee that some two inputs out there can wind up with the same UUID, and as a result, UUIDs are not generally reversible (however, in specific (limited) cases, perhaps they could be made reversible).


1 Answers

You can use UUID this way to get always the same UUID for your input String:

 String aString="JUST_A_TEST_STRING";  String result = UUID.nameUUIDFromBytes(aString.getBytes()).toString(); 
like image 122
uraimo Avatar answered Sep 24 '22 15:09

uraimo