Sometimes we need to generate unique ID for different purpose.Hear is a simple code block to do so. And ready to use .
Sample output : it will differ in every run :
89c9f0ad-7c25-4955-9496-faf802976caf-1337661403009
public static String generateUniqueId () { UUID uuid = UUID.randomUUID(); Date date = new Date(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(uuid.toString()); stringBuilder.append("-"); stringBuilder.append(String.valueOf(date.getTime())); final String UNIQUEID = stringBuilder.toString(); return UNIQUEID; } public static void main (String args[]) { System.out.println(PaymentUtil.generateUniqueId()); }
Sample output : it will differ in every run :
89c9f0ad-7c25-4955-9496-faf802976caf-1337661403009
No comments:
Post a Comment