Time:12-01
CodePudding user response:
List. The sort (new Comparator<linkedHashMap () {@ Override Public int the compare (LinkedHashMap O1, LinkedHashMap O2) {If (o2) get (" aaa ") - o1. Get (" aaa ") & gt; 0 {return 1; } else if (o2) get (" aaa ") - o1. Get (" aaa ") & lt; 0 {return -1; } else {If (o2) get (" BBB ") - o1. Get (" BBB ") & gt; 0 {return 1; } else if (o2. Get. (" BBB ") - o1 get (" BBB ") & lt; 0 {return -1; } else {If (o2) get (" CCC ") - o1. Get (" CCC ") & gt; 0 {return 1; } else if (o2) get (" CCC ") - o1. Get (" CCC ") & lt; 0 {return -1; } else {return 0; } } } } });
String json="[{aaa: 10, BBB: 2, CCC, 6}, \ n +" "{aaa: 6, BBB: 2, CCC: 1}, \ n" + "{aaa: 8, BBB: 3, CCC, 5}, \ n" + "{aaa: 10, BBB: 4, CCC, 4}, \ n" + "{aaa: 10, BBB: 2, CCC: 3}]". List List=JSON. ParseArray (JSON, HashMap class); List Collect=list. Stream () Sorted (Comparator Comparing (o - & gt; Integer. The valueOf (String. The valueOf (((Map) o). Get (" aaa "))), the Comparator. ReverseOrder ()) ThenComparing (o - & gt; Integer. The valueOf (String. The valueOf (((Map) o). Get (" BBB "))), the Comparator. ReverseOrder ()) ThenComparing (o - & gt; Integer. The valueOf (String. The valueOf (((Map) o). Get (" CCC "))), the Comparator. ReverseOrder ()) ) Collect (Collectors. ToList ());
Page link:https//www.codepudding.com/Backend/90631.html