区分String和UUID的万无一失的方法 [英] Foolproof way of differentiating String and UUID

查看:1001
本文介绍了区分String和UUID的万无一失的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个字符串key:< String || UUID>有一种方法可以在<$之后提取字符串并区分该部分c $ c>:是字符串还是UUID?

If I have a string "key:<String || UUID>" is there a way where I can extract the string and differentiate of the part after : is a string or a UUID?

示例:在此键中:863864947148451183L 键:1234
可以使用UUID的大小还是字节数?

Example: in this key:863864947148451183L and key:1234 May be by using the size of a UUID or the number of bytes?

推荐答案

唯一万无一失的方法是使用

The only foolproof way is to use

UUID.fromString(yourString);

它将返回

java.lang.IllegalArgumentException: Invalid UUID string: "someString"

句柄例外。

javadoc 解释了UUID格式。

The javadoc explains the UUID format.

这篇关于区分String和UUID的万无一失的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆