I successfully sort students by id using comparator and displayed using for loop, I hope to know how can I make it happen with iterator, well I tried but only address in console and have no idea of how to print info from Student class
public static void main(String[] args) {
Student stu1 = new Student("Lucy",1000,99);
Student stu2 = new Student("Jack",1001,22);
Student stu3 = new Student("Peter",1002,53);
ArrayList<Student> student = new ArrayList<Student>();
student.add(stu1);
student.add(stu2);
student.add(stu3);
Collections.sort(student,new StuCOmp("id"));
for (int i=0; i<student.size(); i++) {
Student stu = student.get(i);
System.out.println(stu.getName() + " "+stu.getId()+ " "+stu.getGrade());
}
Iterator<Student> it = student.iterator();
while(it.hasNext()){
//what do I write here
}
}