Case Insensitive sorting using Google Guava

佐手、 提交于 2019-12-22 04:43:11

问题


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

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?


回答1:


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


来源:https://stackoverflow.com/questions/6400350/case-insensitive-sorting-using-google-guava

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!