生成32位长,16进制的随机字符串

生成32位长,16进制的随机字符串,也就是UUID,这样可以作为唯一的一个标识。

package cn.itcast.servlet;

import org.junit.Test;

import java.util.UUID;

public class UUIDTest {

    @Test
    public void fun1(){
        UUID uuid = UUID.randomUUID();
        String str = uuid.toString();
        str = str.replace("-","");
        str = str.toUpperCase();
        System.out.println(str);
    }
}

UUID工具类:

package cn.itcast.commons;

import java.util.UUID;

public class CommonUtils {
    public static String uuid(){
        return UUID.randomUUID().toString().replace("-","").toUpperCase();
    }
}

猜你喜欢

转载自blog.csdn.net/yemenlinweihan/article/details/106880974
今日推荐