Package com.yahoo.collections
Class CollectionUtil
- java.lang.Object
-
- com.yahoo.collections.CollectionUtil
-
public class CollectionUtil extends Object
Utilities for java collections- Since:
- 5.1.8
- Author:
- Tony Vaagenes, gjoranv
-
-
Constructor Summary
Constructors Constructor Description CollectionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
equalContentsIgnoreOrder(Collection<?> c1, Collection<?> c2)
Returns true if the contents of the two given collections are equal, ignoring order.static <T> Collection<T>
filter(Collection<?> collection, Class<T> lowerBound)
Returns the subset of elements from the given collection that can be cast to the reference type, defined by the given Class object.static <T> T
first(Collection<T> collection)
Returns the first element in a collection according to iteration order.static <T> Optional<T>
firstMatching(T[] array, Predicate<? super T> predicate)
static String
mkString(Collection<?> collection, String sep)
Returns a String containing the string representation of all elements from the given collection, separated by the separator string.static <T> String
mkString(Collection<T> collection, String start, String sep, String end)
Returns a String containing the string representation of all elements from the given collection, using a start string, separator strings, and an end string.static <T> Set<T>
symmetricDifference(Collection<? extends T> c1, Collection<? extends T> c2)
Returns the symmetric difference between two collections, i.e.
-
-
-
Method Detail
-
mkString
public static String mkString(Collection<?> collection, String sep)
Returns a String containing the string representation of all elements from the given collection, separated by the separator string.- Parameters:
collection
- The collectionsep
- The separator string- Returns:
- A string: elem(0) + sep + ... + elem(N)
-
mkString
public static <T> String mkString(Collection<T> collection, String start, String sep, String end)
Returns a String containing the string representation of all elements from the given collection, using a start string, separator strings, and an end string.- Type Parameters:
T
- The element type- Parameters:
collection
- The collectionstart
- The start stringsep
- The separator stringend
- The end string- Returns:
- A string: start + elem(0) + sep + ... + elem(N) + end
-
equalContentsIgnoreOrder
public static boolean equalContentsIgnoreOrder(Collection<?> c1, Collection<?> c2)
Returns true if the contents of the two given collections are equal, ignoring order.
-
symmetricDifference
public static <T> Set<T> symmetricDifference(Collection<? extends T> c1, Collection<? extends T> c2)
Returns the symmetric difference between two collections, i.e. the set of elements that occur in exactly one of the collections.
-
filter
public static <T> Collection<T> filter(Collection<?> collection, Class<T> lowerBound)
Returns the subset of elements from the given collection that can be cast to the reference type, defined by the given Class object.
-
first
public static <T> T first(Collection<T> collection)
Returns the first element in a collection according to iteration order. Returns null if the collection is empty.
-
-