八位 UUID
2015-09-20 21:44
531 查看
java 生产八位UUID 无重复
package test; import java.util.UUID; public class Test { public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; public static String generateShortUuid() { StringBuffer shortBuffer = new StringBuffer(); String uuid = UUID.randomUUID().toString().replace("-", ""); for (int i = 0; i < 8; i++) { String str = uuid.substring(i * 4, i * 4 + 4); int x = Integer.parseInt(str, 16); shortBuffer.append(chars[x % 0x3E]); } return shortBuffer.toString(); } public static void main(String[] args) { for(int i = 0; i < 1000;i++){ System.out.println(generateShortUuid() + "-------------------------" + i); } } }
相关文章推荐
- uinty3d导入错误问题解决
- iOS 【UIKit-按钮移动操作】
- Longest Consecutive Sequence——Leetcode
- leetcode - N-Queens
- 最小生成树 POJ 3625Building Roads解题报告
- iOS程序-UIScrollView的基本使用
- String、StringBuffer与StringBuilder之间区别
- 【遍历枚举】hdu 5288 OO’s Sequence
- 利用UIEdgeInsets属性修改UIButton的图片,文字位置
- NGUI 源码分析- UIWidgetInspector
- 接口测试工具SoapUI Pro5.1.2基本使用20150920
- 使用EasyUI弹出框页面样式乱了——控制弹出框位置
- codeforces 5C C. Longest Regular Bracket Sequence(dp)
- java中break以及continue
- 黑马程序员——GUI(图形用户界面)中的AWT
- UILabel随文字的多少重置它的frame
- ViewController生命周期
- UI设计-zTree(4)
- 百度编辑器UEditor 简单使用
- UICollectionView实现书本翻页布局