I have an arraylist of multiple arraylists like-
ArrayList<ArrayList<String>> al1=new ArrayList<ArrayList<String>>();
the arraylist contains the elements:
[[Total for all Journals, IOP, IOPscience, , , , , 86, 16, 70, 17, 8, 14, 6, 17, 19, 5], [2D Materials, IOP, IOPscience, 10.1088/issn.2053-1583, 2053-1583, , 2053-1583, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [Acta Physica Sinica (Overseas Edition), IOP, IOPscience, 10.1088/issn.1004-423X, 1004-423X, 1004-423X, , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [Advances in Natural Sciences: Nanoscience and Nanotechnology, IOP, IOPscience, 10.1088/issn.2043-6262, 2043-6262, , 2043-6262, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [Applied Physics Express, IOP, IOPscience, , 1882-0786, 1882-0778, 1882-0786, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
Now i want to sort the main arraylist. Main arraylist contains 5 inner arraylists.Now the sorting must be like the 7th element of every inner arraylist is compared which is integer and inner arraylists are arranged accorting to the value of their 7th element.
Collections.sort(al1, new Comparator<ArrayList<String>>() {
@Override public int compare(ArrayList<String> o1, ArrayList<String> o2) {
return o1.get(7).compareTo(o2.get(7));
}
});
Comparator, and useCollections.sort().