I need to create some uniques files in Java and i plan to use UUID.randomUUID to generate their names. Is there any chance to get a collision for this? Should i do something like bellow os I shouldn't worry about this?
Integer attemptsToGenerateUUID = 1;
while (true) {
UUID fileUUID = UUID.randomUUID();
if (fileDoesNotExistwith this UUID name) {
save file;
break;
}
attemptsToGenerateUUID += 1;
if (attemptsToGenerateUUID > 64) {
return false;
}
}