Groovy 自定义按值对地图进行排序 [英] Groovy custom sort a map by value
本文介绍了Groovy 自定义按值对地图进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张地图,例如
m=[
"james":"silly boy",
"janny":"Crazy girl",
"jimmy":"funny man",
"georges":"massive fella"
];
我想按地图的值对其进行排序,但忽略大小写(这就是为什么需要自定义排序的真正原因).因此我想我必须使用闭包来实现自定义排序.但我是 Groovy 的新手,一直在努力完成这项非常简单的任务!
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!
想要的结果是:
["janny":"Crazy girl", "jimmy":"funny man", "georges":"massive fella", "james":"silly boy"]
谢谢!
推荐答案
要排序不区分大小写,请使用
To sort with case insensitive, use
m.sort { it.value.toLowerCase() }
这篇关于Groovy 自定义按值对地图进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文