Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   How to sort the generic list based om condition (https://www.askmehelpdesk.com/showthread.php?t=813525)

  • Jun 30, 2015, 01:04 AM
    Sagar1988
    How to sort the generic list based om condition
    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.

  • All times are GMT -7. The time now is 12:04 AM.