Let's say I have this ArrayList
of Map
s
def map1 = [key1:value1, key2:value2, key3:value3]
def map2 = [key1:value1, key2:value2, key3:value3]
def map3 = [key1:value1, key2:value2, key3:value3]
def maps = [map1, map2, map3]
I want to sort this list based on value3
of the map.
How can I do that assuming that I'm working in Groovy?
You can create your own custom sort comparator like this in Groovy:
maps.sort { a, b -> a.key3 <=> b.key3 }
This will sort the maps based on the value of each one's key3
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With