How to generate a unique identifier of a fixed length in Java?

Viewed 20480

I am trying to generate a unique identifier of a fixed length such as the IDs that are generated by Megaupload for the uploaded files.

For example:

  • ALGYTAB5
  • BCLD23A6

In this example using from A-Z and 0-9 and with a fixed length of 8 the total different combinations are 2,821,109,907,456.

What if one of the generated id is already taken. Those ids are going to be stored in a database and it shouldn't be used more than once.

How can I achieve that in Java?

Thank you.

4 Answers
Related