I want to use unique id for the files. How can I use system time to generate unique IDs in Java?
You're looking for the UUID
class.
UUID class is what you need.
Sample implementation :
public class RandomStringUUID {
public static void main(String[] args) {
UUID uuid = UUID.randomUUID();
String randomUUIDString = uuid.toString();
System.out.println("Random UUID String = " + randomUUIDString);
System.out.println("UUID version = " + uuid.version());
System.out.println("UUID variant = " + uuid.variant());
}
}
Output :
Random UUID String = 7dc53df5-703e-49b3-8670-b1c468f47f1f
UUID version = 4
UUID variant = 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With