为什么要删除List.sort方法? [英] Why is List.sort method striked through?

查看:95
本文介绍了为什么要删除List.sort方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,我具有错误及其发生次数的映射.我想要一个列表,其中包含该信息的顺序是错误的降序(即,最常见的错误是第一个元素,第二个错误-第二个元素,等等).

I have a map of errors and the number of their occurrences in some situation. I want to have a list, which contains that information in order of descending number of errors (i. e. the most frequent error is first element, the second-most - the second etc.).

我写了以下代码:

List<Map.Entry<String,Integer>> entryList = new ArrayList<>(errors.entrySet());
entryList.sort{a, b -> b.value <=> a.value}    

它工作正常,但sort被删除(在带有Groovy插件的Eclipse IDE中).

It works fine, but the sort is striked through (in Eclipse IDE with the Groovy plugin).

为什么?该方法被淘汰了吗?如果是这样,在Groovy中对列表进行排序的正确方法是什么?

Why? Is that method deperecated? If so, what is the correct way to sort a list in Groovy?

推荐答案

请改用sort的Iterable版本

Use the Iterable version of sort instead

由于弃用-请查看

Because of deprecation - have a look at the docs. Some of sort methods are deprecated in favor of others.

这篇关于为什么要删除List.sort方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆