I hava a structure that is a Map
that contains pairs: String=>Map
.
Is there a way to sort this Map (root) by multiple values? Example to be clear:
Input:
"A" => {name: "John", age: "47"}
"B" => {name: "Sam", age: "60"}
"C" => {name: "Josh", age: "30"}
"D" => {name: "Tom", age: "15"}
"E" => {name: "Josh", age: "31"}
Sorted:
//group 1
"A" => {name: "John", age: "47"}
//group2
"C" => {name: "Josh", age: "30"}
"E" => {name: "Josh", age: "31"}
//group3
"B" => {name: "Sam", age: "60"}
//group4
"D" => {name: "Tom", age: "15"}
Output map is sorted first by name
, then (within sorted groups) by age
.
I am able to sort by single map value entry, but I can't find an easy(-ish) way to sort by multiple entries (in given order). I can try to split this structure after every sort, apply next level sort and join everything at the end, but I am looking for more fancy solution (if there is one).
Any ideas?