public abstract class CollectionUtils extends Object
|Modifier and Type||Method and Description|
Returns a Collection instance that contains the elements of the given
Returns a collection containing the elements that are in both given collections
Merge two collections into a new collection instance.
public static <S,T extends Collection<S>> T merge(T collection1, T collection2, Supplier<T> factoryMethod)
If any of the two inputs collections is
null or empty the other input collection is returned (even if
that one is
null as well).
S- the type of elements in the collections
T- the type of collection
collection1- the first collection
collection2- the second collection
factoryMethod- function to initialize the new collection
public static <R> Collection<R> asCollection(Object potentialCollection)
potentialCollection. If not a Collection-like structure, it will return a Collection with the given
potentialCollectionas the sole element.
The following structures are recognized and will have their elements placed inside a Collection:
R- The type of instance contained in the resulting Collection
potentialCollection- The instance to collect all elements from
public static <T,C extends Collection<T>> C intersect(Collection<? extends T> collection1, Collection<? extends T> collection2, Supplier<C> collectionBuilder)
collection2, using the given
collectionBuilderto create an instance for the new collection. The items are added to the resulting collection in the order as found in collection2.
T- The type of element contained in the resuling collection
C- The type of collection to return
collection1- The first collection
collection2- The second collection
collectionBuilder- The factory for the returned collection instance
Copyright © 2010–2021. All rights reserved.