How safe is it to remove the "-" in a randomly generated UUID?

xybrek :

I have this code:

String uuid = UUID.randomUUID().toString().replace("-", "");

How safe is it to remove the "-" in the generated UUID? Would removing it defeat the purpose of it being globally unique and make the generated UUID prone to collisions?

Malt :

how safe if is to remove the "-" in the generated UUID

It's 100% safe since the dashes aren't part of the value. The String UUID is a hex representation of a 128 bit value. The dashes are there just for display purposes so UUIDs will be a bit easier on the eyes.

Just be careful when passing UUIDs in String form to external systems such as external APIs, databases, and things of that nature. They might be expecting the dashes to be there.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=34901&siteId=1