Java generates a unique random string similar to a token

Sometimes, the background needs to generate a random unique string and provide it to the caller for identity verification.

To generate a random string, you can directly use   the UUID class under the java . util package, which provides us with a generation method , randomUUID().

A method is given below (the horizontal splicing symbol is removed):

 

	/**
	 * 生成token
	 * @return
	 */
	public static String GetGUID()
	{
		return UUID.randomUUID().toString().replace("-", "");
	}

 

 

 

Call result:

5ab0cd25a8c04a6bbd43b30c17cb904d4

 

Ok, just call it directly, yes, it's that simple.

 

Welcome to follow the WeChat public account (Java Practice Notes):

Focus on the accumulation of Java technology, share free Java technology dry goods, study notes, study materials, etc., and strive to make this a Java knowledge station.

 

Guess you like

Origin blog.csdn.net/u012660464/article/details/78759232