If we have list as,
Rollno name age address
====== ==== === =======
01 abc 11 pqr
02 stu 21 pqrWe are supposed to sort this list based on names. If the name of student is same then sort based on age and if age is also same then sort based on number. I am stuck on how to sort names The code that I have tried till is
public void sortData(List<Student> studentList) {
String a1=null;
String a2[] = null;
int I=0;
for (Iterator<Student> iter = list.listIterator(); iter.hasNext();) {
Student a = iter.next();
System.out.println(a1 = a.getStudentName());
}
System.out.println(a2);
}It is printing list of roll numbers but I am not getting how to sort them now.
Rollno name age address
====== ==== === =======
01 abc 11 pqr
02 stu 21 pqrWe are supposed to sort this list based on names. If the name of student is same then sort based on age and if age is also same then sort based on number. I am stuck on how to sort names The code that I have tried till is
public void sortData(List<Student> studentList) {
String a1=null;
String a2[] = null;
int I=0;
for (Iterator<Student> iter = list.listIterator(); iter.hasNext();) {
Student a = iter.next();
System.out.println(a1 = a.getStudentName());
}
System.out.println(a2);
}It is printing list of roll numbers but I am not getting how to sort them now.
How to sort the generic list based om condition
0 commentaires:
Enregistrer un commentaire