I am getting student information from database,
ArrayList<Student> studentList = session.createQuery("from Student order by Date").list();
the studentList contains name , id ,marks, by date. I want to display this arraylist by name, becase the same student name contains different date.
How to sort this from arraylist.
Ex studentList value is
1 x 2010-10-01
2 y 2010-10-05
3 z 2010-10-15
1 x 2010-10-10
1 x 2010-10-17
2 y 2010-10-15
4 xx 2010-10-10
I want to display this to
1 x 2010-10-01
1 x 2010-10-10
1 x 2010-10-17
2 y 2010-10-05
2 y 2010-10-15
3 z 2010-10-15
4 xx 2010-10-10
and store this to another array list
There are plenty of questions to look at that answer this, such as:
https://stackoverflow.com/questions/2784514/sort-arraylist-of-custom-objects-by-property
But here is an example program of what to do. I assumed you wanted to sort by name first, and then date. You can put logic to do that in the custom comparator.
Output of this is:
EDIT: This sorts the array list in place. You’d have to copy it first if you want it as a new list.