package com.hcks.cmfds.commons.util; import java.util.UUID; /** * * @Author 刘厦 (liusha.information@gmail.com) * @Date 创建时间:2011-8-3,上午08:41:05 * @Version 0.0.0 * * 类说明: 自动生成UUID 唯一标识 * */ public class GeneralUUIDHelper { /** * * @return */ public static String newId() { return getUUID(false); } /** * 获取UUID 是否包含"-"分隔符 * @param separator * @return */ private static String getUUID(boolean separator) { String s = UUID.randomUUID().toString(); if(separator) return s; else return s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24); } public static void main(String args[]) { for (int i = 0; i < 100; i++) { System.out.println("GUID+" + i + " = " + GeneralUUIDHelper.newId()); } } }