UUID工具类

 package cc.ccoder.mail.utils;
 
import java.util.UUID;

 /**
 * 
 * @TODO: 生成随机字符串的工具类 uuid
 */
 public class UUIDUtils {

    public static String getUUID(){
          return UUID.randomUUID().toString().replace("-", "");
    }

    public static void main(String[] args) {
        System.out.println("格式前的UUID : " + UUID.randomUUID().toString());
       System.out.println("格式化后的UUID :" + getUUID());
    }
}

 

 

对同一UUID进行操作:

//获取uuid
    public static synchronized String getUUID() {
        String[] arg = UUID.randomUUID().toString().split("-");
        StringBuffer stringBuffer = new StringBuffer();
        for (String str : arg) {
            stringBuffer.append(str);
        }
        return stringBuffer.toString();
    }

 

posted @ 2020-06-21 07:58  酌醉  阅读(266)  评论(0编辑  收藏  举报