Sort list <Map <String, object >>

I have an object below

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

How to sort this based on the value ("Object") on the map?

+4
source share
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 } }); 
+7
source

Use your own comparator (you must implement this interface)

+2
source

Source: https://habr.com/ru/post/1342791/


All Articles