The method generateId allocate ids to students,the method storeStudent is called by the method readData which reads data, the StudentId field in the data are all set to unknown so the method storeStudent replace the word unknown by a unique a id for each student but the problem with it if i have more than 10 student it will repeat the same ids again and I am trying to avoid the id duplication so how can i solve this problem
public void storeStudnet(Student student) {
student.setId(generateCustomerId("AB-",1));
for(Student students : studentList)
{
if(student.getStudentID().equals(student.getStudentID()))
{
student.setId(generateId("AB-",1));
}
}
}
studentList.add(student);
}
public String generateId(int numberaOfDigits)
{
Random random = new Random();
for(int i=0;i<numberaOfDigits;i++)
{
random.nextInt(9);
}
return random.nextInt(9);
}