GeneralUUIDHelper.java 858 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.hcks.cmfds.commons.util;
  2. import java.util.UUID;
  3. /**
  4. *
  5. * @Author 刘厦 (liusha.information@gmail.com)
  6. * @Date 创建时间:2011-8-3,上午08:41:05
  7. * @Version 0.0.0
  8. *
  9. * 类说明: 自动生成UUID 唯一标识
  10. *
  11. */
  12. public class GeneralUUIDHelper {
  13. /**
  14. *
  15. * @return
  16. */
  17. public static String newId() {
  18. return getUUID(false);
  19. }
  20. /**
  21. * 获取UUID 是否包含"-"分隔符
  22. * @param separator
  23. * @return
  24. */
  25. private static String getUUID(boolean separator) {
  26. String s = UUID.randomUUID().toString();
  27. if(separator)
  28. return s;
  29. else
  30. return s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
  31. }
  32. public static void main(String args[]) {
  33. for (int i = 0; i < 100; i++) {
  34. System.out.println("GUID+" + i + " = "
  35. + GeneralUUIDHelper.newId());
  36. }
  37. }
  38. }