//注意replaceAll前面的是正则表达式
String uuid = UUID.randomUUID().toString().replaceAll("-","");
System.out.println(uuid);
// System.out.println(uuid.length());
时间戳:System.currentTimeMillis()
System.out.println(System.currentTimeMillis());
//下面是uuid的生产和检验
public static void main(String[] args) {
// String uuid1 = "e65deb4c-a110-49c8-a4ef-6e69447968d6";
// String uuid2 = "ca4a8a92-d4ed-4fc4-8a4f-345c587fbdcb";
// String uuid3 = "e1f15f1d-6edb-4f70-8a05465se273eaf95a";
// System.out.println("check > " + uuid1 + " > " + isValidUUID(uuid1));
// System.out.println("check > " + uuid2 + " > " + isValidUUID(uuid2));
// System.out.println("check > " + uuid3 + " > " + isValidUUID(uuid3));
// System.out.println("build a uuid> " + getRandomUUID(null));
// System.out.println("build a uuid> " + getRandomUUID(null));
// System.out.println("build a uuid> " + getRandomUUID("kangyucheng"));
// System.out.println("build a uuid> " + getRandomUUID("kangyucheng"));
// String str = "88c2319548484ab790cc063376c097e1";
String str = "88c23195-4848-4ab7-90cc-063376c097e1";
System.out.println(str.length());
System.out.println("check > " + str + " > " + isValidUUID(str));
}
public static boolean isValidUUID(String uuid) {
// UUID校验
if (uuid == null) {
System.out.println("uuid is null");
}
String regex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
if (uuid.matches(regex)) {
return true;
}
return false;
}
public static UUID getRandomUUID(String str) {
// 产生UUID
if (str == null) {
return UUID.randomUUID();
} else {
return UUID.nameUUIDFromBytes(str.getBytes());
}
}