Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting List<Map<String, Object>>

I am having the below object

List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();

How do i sort this based on the value ("Object") in the Map?

like image 986
Madhu Avatar asked Dec 22 '22 17:12

Madhu


2 Answers

Create your own Comparator and use it .

List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
Collections.sort(listMap,new Comparator<Map<String, Object>>() {

            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                //your logic goes here
            }
});
like image 135
jmj Avatar answered Jan 13 '23 19:01

jmj


Use your own Comparator (You have to implement the given interface)

like image 40
Luixv Avatar answered Jan 13 '23 19:01

Luixv