Java generates guid/UUID

Source: Internet
Author: User

Java generates a guid. Using the import class java. util. UUID, the generated GUID is a 32-Bit String of 128-bit data, which can be globally unique.

It is quite easy to generate guids. The following is a demonstration of generating five guids at a time.

 

// Import class

Import java. util. UUID;

 

// Create a primary class

Public class guid
{

// Main Function

Public static void main (string [] ARGs)
{

// Generate 5 guids
For (INT I = 0; I <5; I ++)
{


// Create a guid object
UUID = UUID. randomuuid ();

// Obtain the ID generated by the object
String A = UUID. tostring ();

// Convert to uppercase

A = A. touppercase ();

// Replace-
// A = A. replaceall ("-","");
System. Out. println ();
}
}
}

Output result

20175c27c-a444-4d65-8ffb-b04108321b35
C4264865-385E-4C5B-B78D-3700714E8379
B09EEBBE-1915-497E-850E-015740DA45CF
6ea70626-5006-4db9-84f9-a860a6042a36
3e62b608-0e40-4b80-81b8-e40c3b11958d

 

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.