Groovy custom sort a map by value

groovymapsorting

I have a map such as

m=[
     "james":"silly boy",
     "janny":"Crazy girl",
     "jimmy":"funny man",
     "georges":"massive fella"
];

I want to sort this map by its value but ignoring the case (this is really why the custom sort is needed). Hence I figured I had to implement a custom sort using a closure. But I'm brand new at Groovy and been struggling to get this very simple task done!

The desired results would be:

["janny":"Crazy girl", "jimmy":"funny man", "georges":"massive fella", "james":"silly boy"]

Thanks !

Best Answer

To sort with case insensitive, use

m.sort { it.value.toLowerCase() }