•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 374,512 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,857 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
This class Generate A unique string. You can concatenate Timestamp to this Unique String and use it as Unique ID
package test; /* * @author NAPSTAR */ import java.util.Random; public class XUIDGenerator { private static final int NUM_CHARS = 10; private static String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; private static Random r = new Random(); public static String getUniqueID() { char[] buf = new char[NUM_CHARS]; for (int i = 0; i < buf.length; i++) { buf[i] = chars.charAt(r.nextInt(chars.length())); } return new String(buf); } public static void main(String[] args) { System.out.println(XUIDGenerator.getUniqueID()); } }
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)