1.工具类:
package UUIdtest;import java.util.UUID;public class UUIDUtil {public static String getUUID() {return UUID.randomUUID().toString();}}
2.使用
package UUIdtest;import org.junit.Test;public class TestUUID {@Testpublic void test3(){System.out.println(UUIDUtil.getUUID().replace("-", ""));System.out.println(UUIDUtil.getUUID());System.out.println(UUIDUtil.getUUID());} }
3. 经过改造变成两个,一个带横杠-,一个不带横杠-:
package cn.xm.exam.utils;import java.util.UUID;/*** UUID工具类* * @author QiaoLiQiang* @time 2017年9月18日上午9:09:25*/
public class UUIDUtil {/*** 带-的UUID* * @return 36位的字符串*/public static String getUUID() {return UUID.randomUUID().toString();}/*** 去掉-的UUID* * @return 32位的字符串*/public static String getUUID2() {return UUID.randomUUID().toString().replace("-", "");}}