Is there a function in Java that takes in two strings and generates one 16 character string which is unique to the given combination? I dont expect the string to be 100% unique as long as the probability of having 2 conflicting strings is very small (1 in 100,000 for example). Thanks.
Asked
Active
Viewed 161 times
-3
-
possible duplicate of [Generate UUID in Java](http://stackoverflow.com/questions/325443/generate-uuid-in-java) – APerson Dec 18 '14 at 14:04
-
4Concatenate the strings, then hash the combined string using SHA-1 or similar? – DNA Dec 18 '14 at 14:04
-
could you give us some example? – rzysia Dec 18 '14 at 14:04
-
1read about MessageDigest – Eran Dec 18 '14 at 14:04
-
Thank you for all. I ended up using the method proposed by DNA. – user3245747 Dec 18 '14 at 14:47
2 Answers
1
You can concatenate both strings and hash them.

Marcin Szymczak
- 11,199
- 5
- 55
- 63
-
I'm pretty sure you meant `concatenate`, but I can't edit your post, as changing this one word is too little change. – spoko Dec 18 '14 at 14:13
-
0
If it needs to be truly unique, then a concatenation of the strings which is 16 characters or less is your answer.
Else you have to rely on hashing. But that comes with no guarantee of a probability of clashing.
Your best bet is to use a GUID.

Bathsheba
- 231,907
- 34
- 361
- 483