Top Description Inners Constructors Methods
com.google.common.collect

public final Class Collections2

extends Object
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.collect.CollectPreconditions.checkNonnegative, java.util.Objects.requireNonNull

Provides static methods for working with Collection instances.

Java 8+ users: several common uses for this class are now more comprehensively addressed by the new java.util.stream.Stream library. Read the method documentation below for comparisons. These methods are not being deprecated, but we gently encourage you to migrate to streams.

Authors
Chris Povirk, Mike Bostock, Jared Levy
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class
private static class
private static class
private static class
pack-priv static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static boolean
containsAllImpl(Collection<?>
a collection which might contain all elements in c
self
,
Collection<?>
a collection whose elements might be contained by self
c
)

Returns true if the collection self contains all of the elements in the collection c.

public static <E extends @Nullable Object> Collection<E>
filter(Collection<E> unfiltered, Predicate<? super E> predicate)

Returns the elements of unfiltered that satisfy a predicate.

private static boolean
isPermutation(List<?> first, List<?> second)

Returns true if the second list is a permutation of the first.

pack-priv static StringBuilder
newStringBuilderForCollection(int size)

Returns best-effort-sized StringBuilder based on the given collection size.

public static <E extends Comparable<? super E>> Collection<List<E>>

Returns:

an immutable Collection containing all the different permutations of the original iterable.
orderedPermutations
(Iterable<E>
the original iterable whose elements have to be permuted.
elements
)

Returns a Collection of all the permutations of the specified Iterable.

public static <E> Collection<List<E>>

Returns:

an immutable Collection containing all the different permutations of the original iterable.
orderedPermutations
(Iterable<E>
the original iterable whose elements have to be permuted.
elements
,
Comparator<? super E>
a comparator for the iterable's elements.
comparator
)

Returns a Collection of all the permutations of the specified Iterable using the specified Comparator for establishing the lexicographical ordering.

public static <E> Collection<List<E>>

Returns:

an immutable Collection containing all the different permutations of the original collection.
permutations
(Collection<E>
the original collection whose elements have to be permuted.
elements
)

Returns a Collection of all the permutations of the specified Collection.

pack-priv static boolean
safeContains(Collection<?> collection, Object object)

Delegates to Collection#contains.

pack-priv static boolean
safeRemove(Collection<?> collection, Object object)

Delegates to Collection#remove.

pack-priv static String
toStringImpl(final Collection<?> collection)

An implementation of Collection#toString().

public static <F extends @Nullable Object, T extends @Nullable Object> Collection<T>
transform(Collection<F> fromCollection, Function<? super F, T> function)

Returns a collection that applies function to each element of fromCollection.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait