Package com.yahoo.collections
Class CollectionUtil
- java.lang.Object
-
- com.yahoo.collections.CollectionUtil
-
public class CollectionUtil extends java.lang.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(java.util.Collection<?> c1, java.util.Collection<?> c2)
Returns true if the contents of the two given collections are equal, ignoring order.static <T> java.util.Collection<T>
filter(java.util.Collection<?> collection, java.lang.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(java.util.Collection<T> collection)
Returns the first element in a collection according to iteration order.static <T> java.util.Optional<T>
firstMatching(T[] array, java.util.function.Predicate<? super T> predicate)
static java.lang.String
mkString(java.util.Collection<?> collection, java.lang.String sep)
Returns a String containing the string representation of all elements from the given collection, separated by the separator string.static <T> java.lang.String
mkString(java.util.Collection<T> collection, java.lang.String start, java.lang.String sep, java.lang.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> java.util.Set<T>
symmetricDifference(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2)
Returns the symmetric difference between two collections, i.e.
-
-
-
Method Detail
-
mkString
public static java.lang.String mkString(java.util.Collection<?> collection, java.lang.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> java.lang.String mkString(java.util.Collection<T> collection, java.lang.String start, java.lang.String sep, java.lang.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(java.util.Collection<?> c1, java.util.Collection<?> c2)
Returns true if the contents of the two given collections are equal, ignoring order.
-
symmetricDifference
public static <T> java.util.Set<T> symmetricDifference(java.util.Collection<? extends T> c1, java.util.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> java.util.Collection<T> filter(java.util.Collection<?> collection, java.lang.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(java.util.Collection<T> collection)
Returns the first element in a collection according to iteration order. Returns null if the collection is empty.
-
firstMatching
public static <T> java.util.Optional<T> firstMatching(T[] array, java.util.function.Predicate<? super T> predicate)
-
-