Java generates a unique ID

Source: Internet
Author: User
Tags unique id uuid

Here I use Java provided by the Java.util.UUID class to generate random strings, UUID code is what I will not repeat, can meet our needs.

Here is the Java code:

1 ImportJava.util.UUID;2 3  Public classTest {4     5     PrivateString getId () {6UUID UUID =Uuid.randomuuid ();7          returnUuid.tostring (). Replace ("-", "" ");8     }9     Ten      Public Static voidMain (string[] args) { One         for(inti = 1; I <= 10; i++) { ASystem.out.println ("+i+" secondary cycle: "+NewTest (). GetId ()); -        } -        /* the * 1th cycle: d93d954031ba46f189218b70fb515e81 - 2nd cycle: 39bb777fc3174d3eae567af9c36e9b91 - 3rd cycle: 004cf5d069f242fdaeadb0c3b617a177 - 4th cycle: 1a34a35b3819435a9bf3cf57e84723e3 + 5th cycle: 36bddeeb80cf474692ebb2a820143ac4 - 6th cycle: 14118998dcfb434888fb89cfe86872f6 + 7th cycle: 23d13d893163462e83c735ddeed70324 A 8th cycle: Ac5ea675f91c418cae8b30372d4197a6 at 9th cycle: Fd139e9da15e4b51a8341ae46b6fbdec - 10th cycle: 3f8b227e2f514160a0e0f7abb6fe63db -         */ -     } -}

With simple processing, we can randomly get a 32-character string.

Java generates a unique ID

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.