案例使用Google Guava进行不敏感排序 [英] Case Insensitive sorting using Google Guava

查看:144
本文介绍了案例使用Google Guava进行不敏感排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我在2个不同的地方使用以下2段代码来创建有序的,不可变的列表。

Current I am using the following 2 pieces of code in 2 different places to create a sorted, immutable list.

return Ordering.natural().immutableSortedCopy(iterable);

return Ordering.usingToString().immutableSortedCopy(machines);

然而,这使订购案例敏感

如何使用番石榴apis制作案例 - 不敏感排序的不可变列表?

How do I use the guava apis to make a case-insensitive sorted immutable list?

推荐答案

我相信你需要使用来自方法,带有 String.CASE_INSENSITIVE_ORDER 比较器,如下所示。

I believe you will need to use the from method with the String.CASE_INSENSITIVE_ORDER comparator, like this.

return Ordering.from(String.CASE_INSENSITIVE_ORDER).immutableSortedCopy(iterable);

这篇关于案例使用Google Guava进行不敏感排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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