问题是我无法创建唯一的学生编号,有时我在存储学生时得到相同的学生 ID,是否有生成唯一的学生 ID 编号,我需要修改存储方法以便创建唯一的
public class Collection
{
private ArrayList<Student> studentList;
public Collection()
{
studentList = new ArrayList<Student>();
}
public void storeStudent(Student student)
{
student.setId(createId("AB",9));
studentList.add(student);
}
public String createId(String pre, int number)
{
Random random = new Random();
int index = random.nextInt(number);
return pre + index + " ";
}
}
public class Student
{
private String studentId;
private String name;
public Student( String name)
{
studentId = "UnKnow";
this.name = name;
}
public void setId(String id)
{
studentId = id;
}
}