Java 有没有办法从字符串生成相同的 UUID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29059530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:17:37  来源:igfitidea点击:

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

javauuid

提问by Adam Lee

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.

我想知道是否有一种方法可以根据String.我尝试使用 UUID生成相同的UUID,它似乎不提供此功能。

采纳答案by Umberto Raimondi

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

您可以通过这种方式使用 UUID 来始终为您的输入字符串获取相同的 UUID:

 String aString="JUST_A_TEST_STRING";
 String result = UUID.nameUUIDFromBytes(aString.getBytes()).toString();