Class CollectionTool

java.lang.Object
com.xxl.tool.core.CollectionTool

public class CollectionTool extends Object
Collection Tool
Author:
xuxueli 2024-01-21 05:03:10 (some references to other libraries)
  • Constructor Details

    • CollectionTool

      public CollectionTool()
  • Method Details

    • 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
    • isNotEmpty

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

      Null returns false.

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

      public static boolean contains(Collection<?> collection, Object value)
      Returns true if the value in collections.
      Parameters:
      collection -
      value -
      Returns:
    • union

      public static Collection union(Collection a, Collection b)
      并集 Returns a Collection containing the union of the given Collections.
      Parameters:
      a - the first collection, must not be null
      b - the second collection, must not be null
      Returns:
      the union of the two collections
      See Also:
    • 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
    • intersection

      public static Collection intersection(Collection a, Collection b)
      交集 Returns a Collection containing the intersection of the given Collections.
      Parameters:
      a - the first collection, must not be null
      b - the second collection, must not be null
      Returns:
      the intersection of the two collections
    • disjunction

      public static Collection disjunction(Collection a, Collection b)
      交集的补集 Returns a Collection containing the exclusive disjunction (symmetric difference) of the given Collections.
      Parameters:
      a - the first collection, must not be null
      b - the second collection, must not be null
      Returns:
      the symmetric difference of the two collections
    • subtract

      public static Collection subtract(Collection a, Collection b)
      A与B的差 (A-B) Returns a new Collection containing a - b.
      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:
    • newArrayList

      public static <E> ArrayList<E> newArrayList()
      bulid new ArrayList
      Type Parameters:
      E -
      Returns:
    • newArrayList

      public static <E> ArrayList<E> newArrayList(E... elements)
      bulid new ArrayList (with data)
      Type Parameters:
      E -
      Parameters:
      elements -
      Returns:
    • split

      public static <E> List<List<E>> split(List<E> list, int batchSize)
      split to batch-list
      Type Parameters:
      E -
      Parameters:
      list -
      batchSize -
      Returns: