Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case Insensitive sorting using Google Guava

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?

like image 894
pdeva Avatar asked Jun 19 '11 03:06

pdeva


1 Answers

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);
like image 117
Pablo Fernandez Avatar answered Nov 01 '22 19:11

Pablo Fernandez