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?
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.