Class CollectionUtils


  • public class CollectionUtils
    extends Object
    Provides utility methods and decorators for Collection instances.
    Since:
    Commons Collections 1.0
    Version:
    $Revision: 1713167 $ $Date: 2015-11-07 20:44:03 +0100 (Sat, 07 Nov 2015) $
    Author:
    Rodney Waldhoff, Paul Jack, Stephen Colebourne, Steve Downey, Herve Quiroz, Peter KoBek, Matthew Hawthorne, Janek Bogucki, Phil Steitz, Steven Melzer, Jon Schewe, Neil O'Toole, Stephen Smith
    • Constructor Detail

      • CollectionUtils

        public CollectionUtils()
        CollectionUtils should not normally be instantiated.
    • Method Detail

      • subtract

        public static Collection subtract​(Collection a,
                                          Collection b)
        Returns a new Collection containing a - b. The cardinality of each element e in the returned Collection will be the cardinality of e in a minus the cardinality of e in b, or zero, whichever is greater.
        Parameters:
        a - the collection to subtract from, must not be null
        b - the collection to subtract, must not be null
        Returns:
        a new collection with the results
        See Also:
        Collection.removeAll(java.util.Collection<?>)
      • getCardinalityMap

        public static Map getCardinalityMap​(Collection coll)
        Returns a Map mapping each unique element in the given Collection to an Integer representing the number of occurrences of that element in the Collection.

        Only those elements present in the collection will appear as keys in the map.

        Parameters:
        coll - the collection to get the cardinality map for, must not be null
        Returns:
        the populated cardinality map
      • isEqualCollection

        public static boolean isEqualCollection​(Collection a,
                                                Collection b)
        Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities.

        That is, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b.

        Parameters:
        a - the first collection, must not be null
        b - the second collection, must not be null
        Returns:
        true iff the collections contain the same elements with the same cardinalities.
      • isEmpty

        public static boolean isEmpty​(Collection coll)
        Null-safe check if the specified collection is empty.

        Null returns true.

        Parameters:
        coll - the collection to check, may be null
        Returns:
        true if empty or null
        Since:
        Commons Collections 3.2