com.google.common.collect
Class Collections2

java.lang.Object
  extended by com.google.common.collect.Collections2

public final class Collections2
extends java.lang.Object

Provides static methods for working with Collection instances.

Author:
Chris Povirk, Mike Bostock, Jared Levy

Method Summary
static
<E> java.util.Collection<E>
filter(java.util.Collection<E> unfiltered, Predicate<? super E> predicate)
          Returns the elements of unfiltered that satisfy a predicate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

filter

public static <E> java.util.Collection<E> filter(java.util.Collection<E> unfiltered,
                                                 Predicate<? super E> predicate)
Returns the elements of unfiltered that satisfy a predicate. The returned collection is a live view of unfiltered; changes to one affect the other.

The resulting collection's iterator does not support remove(), but all other collection methods are supported. The collection's add() and addAll() methods throw an IllegalArgumentException if an element that doesn't satisfy the predicate is provided. When methods such as removeAll() and clear() are called on the filtered collection, only elements that satisfy the filter will be removed from the underlying collection.

The returned collection isn't threadsafe or serializable, even if unfiltered is.

Many of the filtered collection's methods, such as size(), iterate across every element in the underlying collection and determine which elements satisfy the filter. When a live view is not needed, it may be faster to copy the filtered collection and use the copy.



Copyright © 2007-2009 Google. All Rights Reserved.