Basically I have a List<Map<String,Object>>
, and I want to sort it by the values of certain key in the map.
The problem is that I do not know the type... This map can contain Strings, Integers, Doubles, Floats etc.... I would like to sort it:
So far
List<Map<String,Object>> data = getResults();
Collections.sort(data, (o1, o2) -> (String.valueOf(o2.get("Field1")))
.compareTo((String.valueOf(o1.get("Field1")))));
It is not a great Idea since numbers are not properly sorted.... How can I handle this?