开发者

Case Insensitive sorting using Google Guava

开发者 https://www.devze.com 2023-03-14 08:35 出处:网络
Current I am using the following 2 pieces of code in 2 different places to create a开发者_StackOverflow中文版 sorted, immutable list.

Current I am using the following 2 pieces of code in 2 different places to create a开发者_StackOverflow中文版 sorted, immutable list.

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

and

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

However, this makes the 'ordering' case sensitive.

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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消