生成uuid 和 检验

摘要:
//请注意,replaceAll前面是正则表达式Stringuuid=UUID。randomUUID()。toString()。replaceAll(“-”,“”);System.out.println(uuid);//System.out.println(uuid.length());时间戳:系统。currentTimeMillis()系统。出来println(System.c

//注意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());
}
}

免责声明:文章转载自《生成uuid 和 检验》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇基於tiny4412的Linux內核移植 --- 实例学习中断背后的知识(1)Web Service学习之八:Soap消息详解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

无法启动计算机“”上的服务 ReportServer 错误1053:服务没有及时响应启动或控制请求

背景: 网络组同事在服务器上安装防病毒软件并且修改了administrator帐号的密码,然后重启电脑后,reproting services就无法启动了。 出现错误如下: 1.报表服务器网页显示错误 System.InvalidOperationException: 无法启动计算机“ ”上的服务 ReportServer。 ---> System....

iOS设备的标识---UUID和IDFA

一:1.1 :UDID 简介:UDID的全称是Unique Device Identifier,顾名思义,它就是苹果IOS设备的唯一识别码,它由40个字符的字母和数字组成。在很多需要限制一台设备一个账号的应用中经常会用到。在iOS5中可以获取到设备的UDID,iOS7中已经完全的禁用了它。iOS7之前的使用了的app如果在iOS7上运行,它不会返回设备...

Val简介(来源维基百科)

1.中文版 网址:http://zh.wikipedia.org/wiki/%E5%8F%AF%E5%8F%98%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80 可变汇编语言(Variable Assembly Language,VAL)是一个设计给Unimation Inc.工业机器人用的电脑控制系统及编程语言。VAL机器人语言是会...

postgresql-无序uuid tps测试

# postgresql-无序uuid tps测试## 无序uuid对数据库的影响由于最近在做超大表的性能测试,在该过程中发现了无序uuid做主键对表插入性能有一定影响。结合实际情况发现当表的数据量越大,对表插入性能的影响也就越大。### 测试环境PostgreSQL创建插入脚本,测试各种情况的tps。数据库版本:PostgreSQL 10.4 (Arte...

获取Android设备唯一标识码

概述 有时需要对用户设备进行标识,所以希望能够得到一个稳定可靠并且唯一的识别码。虽然Android系统中提供了这样设备识别码,但是由于Android系统版本、厂商定制系统中的Bug等限制,稳定性和唯一性并不理想。而通过其他硬件信息标识也因为系统版本、手机硬件等限制存在不同程度的问题。 下面收集了一些“有能力”或“有一定能力”作为设备标识的串码。 DE...

C#数组段ArraySegment<T>的使用

//数组段ArraySegment<T>的使用 using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; namespace ss { class Program...