I have a class (below). I have the field id for the class but I dont know how to make this create a unique id increasing sequentially.
I found that UUID.randomUUID(); would generate a unique ID but in a very unfriendly way and with no way to limit size.
How could I implement something to increase the id field as objects are created from the below class?
class Customer {
public int id;
public String name;
public String email;
public String number;
public String issue;
public String expiry;
Customer(String eName, String eEmail, String eNumber, String eIssue, String eExpiry)
{
id = 0935091285;
name = eName;
email = eEmail;
number = eNumber;
issue = eIssue;
expiry = eExpiry;
}
}
You don’t specify whether you have multiple processes simultaneously generating ids. If you don’t, the following is simple and will work well:
Format the numeric id with leading zeroes if you’d like lexicographic ordering of ids to reflect object creation order.