I have a List
List<Map<String,String>> list = new ArrayList<>();
Map<String,String> map = new HashMap<>();
Map<String,String> map1 = new HashMap<>();
Map<String,String> map2 = new HashMap<>();
map.put("productNumber", "107-001");
map1.put("productNumber", "108-001");
map2.put("productNumber", "109-001");
map.put("price", "1.99");
map1.put("price", "1.02");
map2.put("price", "1.99");
list.add(map);
list.add(map1);
list.add(map2);
I sort it by price and revers result
formattedResult = list.stream().sorted(Comparator.comparing(m -> Double.parseDouble(m.get("price")))).collect(Collectors.toList());
Collections.reverse(formattedResult);
The result of this :
**price productNumber**
1.99 109-001
1.99 107-001
1.02 108-001
I want to sort it like
**price productNumber**
1.99 107-001
1.99 109-001
1.02 108-001
If prices equal - compare by product number, end first should be productNumber with a lower value. Please help!