Why Lists does not have a filter method

2 views
Skip to first unread message

ralph23

unread,
Sep 16, 2009, 4:51:45 AM9/16/09
to Google Collections Library - users list
Hi

I'm wondering why the class com.google.common.collect.Lists does not
have a filter method. Sets has a fillter method and Maps has
filterKeys and filterValues method.

I could use com.google.common.collect.Collections2.filter for
filtering a list but this method gives me a Collection back and not a
List.


Regards
Ralph

Kevin Bourrillion

unread,
Sep 16, 2009, 10:48:03 AM9/16/09
to ralph23, Google Collections Library - users list
We are suspicious of the value of Lists.filter().  The only reason to want a List back is for its index-based methods like get(5), but these methods would perform abysmally on a filtered List.  We think ImmutableList.copyOf(Iterables.filter()) is usually a better way.
--
Kevin Bourrillion @ Google
internal:  http://go/javalibraries
google-collections.googlecode.com
google-guice.googlecode.com

ralph23

unread,
Sep 16, 2009, 1:34:55 PM9/16/09
to Google Collections Library - users list
Hi

Thanks for the explanation. I understand now why there is no such
method in Lists.
Thanks a lot

Ralph
Reply all
Reply to author
Forward
0 new messages