简体   繁体   中英

Java algorithm to create own unique key

I want to create an own unique key which is 6 characters long and includes the following regex characters and numbers: [az][0-9] eg: 00000A, 00000B, ... 00000Z, 00001A, 00001B,...

I don't know how to create this algorithm of these regex formation.

Has someone an idea, how to create this algorithm?

First, your regexp does not match the numbers you're showing as examples. So you'd need to make up your mind there :)

Second, you can simply use a base-36 number probably, and somehow keep track of the last number generated (eg using a properties file or database field) in a synchronized singleton.

Then create a simple method that turns the number into a String and left pad that number with zeros until you reach the desired length.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM