package com.myTest; import java.util.UUID; import java.util.zip.CRC32; /** * UUID操做類 * @author */ public class UUIDTest { /** * 生成32位的UUID,去掉"-"符號 * @return 返回生成的UUID */ public static String getUUID() { UUID uuid = UUID.randomUUID(); String str = uuid.toString(); // 去掉"-"符號 String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24); System.out.println(temp); return temp; } /** * 生成32位的UUID * @return */ public static UUID getUUID1() { UUID uuid = UUID.randomUUID(); System.out.println(uuid); return uuid; } /** * 根據UUID生成CRC的校驗碼 * @param string * @return */ private static String mkCrc(String string) { CRC32 crc32 = new CRC32(); crc32.update(string.getBytes()); return Long.toHexString(crc32.getValue()); } /** * main 測試方法 * @param args */ public static void main(String[] args) { String temp = getUUID(); System.out.println(mkCrc(temp)); System.out.println(temp.length()); } }