Class CollUtil

java.lang.Object
com.sure.tool.collection.CollUtil

public class CollUtil extends Object
集合工具类,参考 Hutool 的 CollUtil 设计。

English: Collection helpers for creating, filtering, joining and comparing lists, sets and maps.

Since:
0.1.0
Author:
suretool
  • Method Details

    • isEmpty

      public static boolean isEmpty(Collection<?> collection)
      集合是否为空。
      Parameters:
      collection - 集合
      Returns:
      是否为空
    • isNotEmpty

      public static boolean isNotEmpty(Collection<?> collection)
      集合是否非空。
      Parameters:
      collection - 集合
      Returns:
      是否非空
    • isEmpty

      public static boolean isEmpty(Map<?,?> map)
      Map 是否为空。
      Parameters:
      map - Map
      Returns:
      是否为空
    • isNotEmpty

      public static boolean isNotEmpty(Map<?,?> map)
      Map 是否非空。
      Parameters:
      map - Map
      Returns:
      是否非空
    • isEmpty

      public static boolean isEmpty(Iterator<?> iterator)
      迭代器是否为空。
      Parameters:
      iterator - 迭代器
      Returns:
      是否为空
    • isEmpty

      public static boolean isEmpty(Enumeration<?> enumeration)
      枚举是否为空。
      Parameters:
      enumeration - 枚举
      Returns:
      是否为空
    • isEmpty

      public static boolean isEmpty(Object array)
      数组是否为空。
      Parameters:
      array - 数组
      Returns:
      是否为空
    • newArrayList

      @SafeVarargs public static <T> List<T> newArrayList(T... values)
      创建 ArrayList。
      Type Parameters:
      T - 元素类型
      Parameters:
      values - 元素
      Returns:
      ArrayList
    • newHashSet

      @SafeVarargs public static <T> HashSet<T> newHashSet(T... values)
      创建 HashSet。
      Type Parameters:
      T - 元素类型
      Parameters:
      values - 元素
      Returns:
      HashSet
    • newLinkedHashSet

      @SafeVarargs public static <T> LinkedHashSet<T> newLinkedHashSet(T... values)
      创建 LinkedHashSet。
      Type Parameters:
      T - 元素类型
      Parameters:
      values - 元素
      Returns:
      LinkedHashSet
    • contains

      public static boolean contains(Collection<?> collection, Object value)
      集合是否包含指定元素。
      Parameters:
      collection - 集合
      value - 元素
      Returns:
      是否包含
    • containsAny

      public static boolean containsAny(Collection<?> collection, Object... values)
      集合是否包含任一指定元素。
      Parameters:
      collection - 集合
      values - 元素数组
      Returns:
      是否包含任一元素
    • union

      public static <T> List<T> union(Collection<T> c1, Collection<T> c2)
      并集(去重)。
      Type Parameters:
      T - 元素类型
      Parameters:
      c1 - 集合 1
      c2 - 集合 2
      Returns:
      并集
    • intersection

      public static <T> List<T> intersection(Collection<T> c1, Collection<T> c2)
      交集(去重)。
      Type Parameters:
      T - 元素类型
      Parameters:
      c1 - 集合 1
      c2 - 集合 2
      Returns:
      交集
    • disjunction

      public static <T> List<T> disjunction(Collection<T> c1, Collection<T> c2)
      差集(属于 c1 但不属于 c2)。
      Type Parameters:
      T - 元素类型
      Parameters:
      c1 - 集合 1
      c2 - 集合 2
      Returns:
      差集
    • xor

      public static <T> List<T> xor(Collection<T> c1, Collection<T> c2)
      对称差集(属于 c1 或 c2 但不同时属于两者)。
      Type Parameters:
      T - 元素类型
      Parameters:
      c1 - 集合 1
      c2 - 集合 2
      Returns:
      对称差集
    • join

      public static String join(Collection<?> collection, CharSequence delimiter)
      拼接集合元素。
      Parameters:
      collection - 集合
      delimiter - 分隔符
      Returns:
      拼接结果
    • toList

      public static <T> List<T> toList(Iterable<T> iterable)
      集合转 List(安全拷贝)。
      Type Parameters:
      T - 元素类型
      Parameters:
      iterable - 可迭代集合
      Returns:
      List,空集合返回空列表
    • toList

      public static <T> List<T> toList(Iterator<T> iterator)
      迭代器转 List。
      Type Parameters:
      T - 元素类型
      Parameters:
      iterator - 迭代器
      Returns:
      List
    • toList

      public static <T> List<T> toList(Enumeration<T> enumeration)
      枚举转 List。
      Type Parameters:
      T - 元素类型
      Parameters:
      enumeration - 枚举
      Returns:
      List
    • get

      public static <T> T get(Collection<T> collection, int index)
      获取指定索引的元素(负数从末尾倒数)。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      index - 索引
      Returns:
      元素,越界返回 null
    • get

      public static <T> T get(Collection<T> collection, int index, T defaultValue)
      获取集合中指定索引的元素,越界或空集合时返回默认值。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      index - 索引(支持负索引,-1 表示倒数第一个)
      defaultValue - 默认值
      Returns:
      元素或默认值
    • getFirst

      public static <T> T getFirst(Collection<T> collection)
      获取第一个元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      Returns:
      第一个元素
    • getLast

      public static <T> T getLast(Collection<T> collection)
      获取最后一个元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      Returns:
      最后一个元素
    • filter

      public static <T> List<T> filter(Collection<T> collection, Predicate<T> predicate)
      过滤集合(返回新列表)。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      predicate - 过滤条件
      Returns:
      过滤后的列表
    • map

      public static <T,R> List<R> map(Collection<T> collection, Function<T,R> mapper)
      映射集合元素(返回新列表)。
      Type Parameters:
      T - 源元素类型
      R - 目标元素类型
      Parameters:
      collection - 集合
      mapper - 映射函数
      Returns:
      映射后的列表
    • groupByKey

      public static <T,K> Map<K,List<T>> groupByKey(Collection<T> collection, Function<T,K> keyMapper)
      按 key 分组。
      Type Parameters:
      T - 元素类型
      K - key 类型
      Parameters:
      collection - 集合
      keyMapper - key 提取函数
      Returns:
      分组 Map
    • distinct

      public static <T> List<T> distinct(Collection<T> collection)
      去重(保持原有顺序)。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      Returns:
      去重后的列表
    • sort

      public static <T> List<T> sort(Collection<T> collection, Comparator<T> comparator)
      排序(返回新列表)。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      comparator - 比较器
      Returns:
      排序后的列表
    • size

      public static int size(Collection<?> collection)
      集合大小。
      Parameters:
      collection - 集合
      Returns:
      大小,空集合返回 0
    • sub

      public static <T> List<T> sub(List<T> list, int from, int to)
      截取列表子区间(负数索引从末尾倒数)。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      from - 起始索引(含)
      to - 结束索引(不含)
      Returns:
      子列表
    • reverse

      public static <T> List<T> reverse(List<T> list)
      反转列表(原地反转)。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      Returns:
      反转后的列表
    • emptyIfNull

      public static <T> List<T> emptyIfNull(Collection<T> collection)
      空集合返回空列表。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      Returns:
      非空返回原列表,否则返回空列表
    • isEmpty

      public static boolean isEmpty(Iterable<?> iterable)
      Iterable 是否为空。
      Parameters:
      iterable - 可迭代对象
      Returns:
      是否为空
    • page

      public static <T> List<T> page(List<T> list, int page, int size)
      分页(页码从 1 开始),越界时返回空列表。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 原列表
      page - 页码(>=1)
      size - 每页条数(>0)
      Returns:
      当前页元素列表
    • shuffle

      public static <T> List<T> shuffle(List<T> list)
      就地洗牌(Fisher-Yates),返回原列表以便链式调用。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      Returns:
      洗牌后的原列表
    • countMap

      public static <T> Map<T,Integer> countMap(Collection<T> collection)
      统计元素出现频次。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      Returns:
      元素到频次的映射
    • subtract

      public static <T> List<T> subtract(Collection<T> c1, Collection<T> c2)
      单向差集:返回 c1 中存在但 c2 中不存在的元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      c1 - 左集合
      c2 - 右集合
      Returns:
      c1 - c2 的结果列表
    • toMap

      public static <T,K,V> Map<K,V> toMap(Collection<T> collection, Function<T,K> keyMapper, Function<T,V> valueMapper)
      列表转映射。
      Type Parameters:
      T - 元素类型
      K - key 类型
      V - value 类型
      Parameters:
      collection - 集合
      keyMapper - key 提取函数
      valueMapper - value 提取函数
      Returns:
      映射(重复 key 时后者覆盖前者)
    • addAll

      public static <T> Collection<T> addAll(Collection<T> target, Collection<T> source)
      将 source 全部追加到 target 并返回 target。
      Type Parameters:
      T - 元素类型
      Parameters:
      target - 目标集合
      source - 源集合
      Returns:
      target
    • containsAll

      @SafeVarargs public static <T> boolean containsAll(Collection<T> collection, T... values)
      是否包含全部指定元素。
      Parameters:
      collection - 集合
      values - 要检查的元素
      Returns:
      是否全部包含
    • containsAll

      public static boolean containsAll(Collection<?> collection, Collection<?> target)
      是否包含另一集合全部元素。
      Parameters:
      collection - 集合
      target - 目标集合
      Returns:
      是否全部包含
    • sortByProperty

      public static <T> List<T> sortByProperty(Collection<T> collection, String property)
      按属性升序排序。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      property - 属性名
      Returns:
      排序后的列表
    • sortByProperty

      public static <T> List<T> sortByProperty(Collection<T> collection, String property, boolean isAscending)
    • split

      public static <T> List<List<T>> split(List<T> list, int groupSize)
      按固定大小切分为多组。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      groupSize - 每组大小(>0)
      Returns:
      分组列表
    • sum

      public static int sum(Collection<Integer> coll)
      int 集合求和。
      Parameters:
      coll - 集合
      Returns:
      和
    • sumLong

      public static long sumLong(Collection<Long> coll)
      long 集合求和。
      Parameters:
      coll - 集合
      Returns:
      和
    • sumDouble

      public static double sumDouble(Collection<Double> coll)
      double 集合求和。
      Parameters:
      coll - 集合
      Returns:
      和
    • min

      public static <T extends Comparable<? super T>> T min(Collection<T> collection)
      最小值(Comparable 集合,null 安全)。
      Type Parameters:
      T - 元素类型(Comparable)
      Parameters:
      collection - 集合
      Returns:
      最小值;空集合返回 null
    • max

      public static <T extends Comparable<? super T>> T max(Collection<T> collection)
      最大值(Comparable 集合,null 安全)。
      Type Parameters:
      T - 元素类型(Comparable)
      Parameters:
      collection - 集合
      Returns:
      最大值;空集合返回 null
    • listToMap

      public static <T,K> Map<K,T> listToMap(Collection<T> list, Function<T,K> keyFunction)
      List 转 Map(key 由函数提取,重复 key 后值覆盖)。
      Type Parameters:
      T - 元素类型
      K - 键类型
      Parameters:
      list - 列表
      keyFunction - 键提取函数
      Returns:
      Map
    • minBy

      public static <T, R extends Comparable<R>> T minBy(Collection<T> collection, Function<T,R> keyMapper)
      按提取函数取最小值。
      Type Parameters:
      T - 元素类型
      R - 键类型
      Parameters:
      collection - 集合
      keyMapper - 提取函数
      Returns:
      最小元素;空集合返回 null
    • maxBy

      public static <T, R extends Comparable<R>> T maxBy(Collection<T> collection, Function<T,R> keyMapper)
      按提取函数取最大值。
      Type Parameters:
      T - 元素类型
      R - 键类型
      Parameters:
      collection - 集合
      keyMapper - 提取函数
      Returns:
      最大元素;空集合返回 null
    • zip

      public static <K,V> Map<K,V> zip(Collection<K> keys, Collection<V> values)
      将两个集合按顺序配对为 Map。
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      keys - 键集合
      values - 值集合
      Returns:
      配对后的 Map(LinkedHashMap,取较短长度)
    • removeNull

      public static <T> List<T> removeNull(Collection<T> coll)
      移除集合中的 null 元素,返回新列表。
      Type Parameters:
      T - 元素类型
      Parameters:
      coll - 集合
      Returns:
      不含 null 的新列表
    • sortByPropertyDesc

      public static <T> List<T> sortByPropertyDesc(Collection<T> collection, String property)
      按属性降序排序。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      property - 属性名
      Returns:
      排序后的列表
    • indexOf

      public static <T> int indexOf(List<T> list, Object value)
      在列表中查找元素下标。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      value - 元素
      Returns:
      下标或 -1
    • lastIndexOf

      public static <T> int lastIndexOf(List<T> list, Object value)
      在列表中查找元素最后出现的下标。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      value - 元素
      Returns:
      下标或 -1
    • chunk

      public static <T> List<List<T>> chunk(Collection<T> collection, int size)
      将集合按指定大小分片。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 输入集合,可为空
      size - 每片大小,必须大于 0
      Returns:
      分片列表;输入为空时返回空列表
      Throws:
      IllegalArgumentException - size 不大于 0
      Since:
      1.1.0
    • randomItem

      public static <T> T randomItem(Collection<T> collection)
      从集合中随机取一个元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 输入集合,不允许为空
      Returns:
      随机元素
      Throws:
      IllegalArgumentException - 集合为空
      Since:
      1.1.0
    • randomItems

      public static <T> List<T> randomItems(Collection<T> collection, int count)
      从集合中随机取指定数量的元素(不重复)。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 输入集合,可为空
      count - 取样数量
      Returns:
      随机取样列表;count 不大于 0 时返回空列表
      Since:
      1.1.0
    • toImmutable

      public static <T> List<T> toImmutable(Collection<T> collection)
      返回集合的不可变副本。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 输入集合,可为空
      Returns:
      不可变列表;输入为空时返回空列表
      Since:
      1.1.0
    • frequency

      public static <T> int frequency(Collection<T> collection, T value)
      统计元素在集合中出现的次数(基于 Objects.equals(Object, Object))。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 输入集合,可为空
      value - 目标元素
      Returns:
      出现次数
      Since:
      1.1.0
    • rotate

      public static <T> List<T> rotate(List<T> list, int steps)
      旋转列表元素(正数为右旋,负数为左旋)。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      steps - 旋转步数(可为负)
      Returns:
      原列表(原地操作)
    • removeEmpty

      public static <T> Collection<T> removeEmpty(Collection<T> collection)
      移除集合中的 null 与空元素(空字符串/空集合/空 Map)。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      Returns:
      过滤后的集合(原地移除)
    • removeAny

      @SafeVarargs public static <T> Collection<T> removeAny(Collection<T> collection, T... values)
      移除集合中的指定元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      values - 要移除的元素
      Returns:
      过滤后的集合(原地移除)
    • isAllEmpty

      @SafeVarargs public static boolean isAllEmpty(Collection<?>... collections)
      判断多个集合是否全部为空(null 或空集合视为空)。
      Parameters:
      collections - 集合数组
      Returns:
      全部为空返回 true
    • isAllNotNull

      @SafeVarargs public static boolean isAllNotNull(Collection<?>... collections)
      判断多个集合是否全部非空(非 null 且非空集合)。
      Parameters:
      collections - 集合数组
      Returns:
      全部非空返回 true
    • newTreeSet

      @SafeVarargs public static <T> TreeSet<T> newTreeSet(Comparator<? super T> comparator, T... values)
      创建带比较器的有序 Set(TreeSet),并填充元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      comparator - 比较器(可空,空则自然序)
      values - 元素
      Returns:
      TreeSet
      Since:
      1.10.0
    • newConcurrentHashSet

      @SafeVarargs public static <T> Set<T> newConcurrentHashSet(T... values)
      创建线程安全的 Set(基于 ConcurrentHashMap),并填充元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      values - 元素
      Returns:
      并发 Set
      Since:
      1.10.0
    • flatMap

      public static <T> List<T> flatMap(Collection<? extends Collection<? extends T>> nested)
      展平一层嵌套集合。
      Type Parameters:
      T - 元素类型
      Parameters:
      nested - 嵌套集合(内层可为空)
      Returns:
      展平后的列表
      Since:
      1.10.0
    • swap

      public static <T> List<T> swap(List<T> list, int index1, int index2)
      交换列表中两个位置的元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 列表
      index1 - 位置一
      index2 - 位置二
      Returns:
      本列表,支持链式调用
      Throws:
      IndexOutOfBoundsException - 下标越界
      Since:
      1.10.0
    • toArray

      public static <T> T[] toArray(Iterable<T> iterable, Class<T> type)
      集合转数组。
      Type Parameters:
      T - 元素类型
      Parameters:
      iterable - 可迭代对象
      type - 数组元素类型
      Returns:
      数组
      Since:
      1.10.0
    • maxCount

      public static <T> T maxCount(Collection<T> collection)
      返回集合中出现次数最多的元素(众数);并列时取先出现的元素。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      Returns:
      众数元素;集合为空返回 null
      Since:
      1.10.0
    • containsAny

      public static boolean containsAny(Collection<?> c1, Collection<?> c2)
      两个集合是否存在交集。
      Parameters:
      c1 - 集合一
      c2 - 集合二
      Returns:
      存在交集返回 true
      Since:
      1.10.0
    • partitionBy

      public static <T> Partition<T> partitionBy(Collection<T> collection, Predicate<T> predicate)
      按谓词将集合分为「匹配」与「不匹配」两部分(均保序),等价于一次性完成 filter 与其补集。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 待分集合(null 按空集合处理)
      predicate - 匹配谓词(null 时抛 NullPointerException)
      Returns:
      二分结果 Partition
      Since:
      1.15.0
    • groupBy2

      public static <T,K1,K2> Map<K1, Map<K2,List<T>>> groupBy2(Collection<T> collection, Function<T,K1> keyMapper1, Function<T,K2> keyMapper2)
      按两级键进行嵌套分组:先按 keyMapper1 分组,组内再按 keyMapper2 分组(均保序)。
      Type Parameters:
      T - 元素类型
      K1 - 一级键类型
      K2 - 二级键类型
      Parameters:
      collection - 待分组集合(null 按空集合处理)
      keyMapper1 - 一级键映射(null 时抛 NullPointerException)
      keyMapper2 - 二级键映射(null 时抛 NullPointerException)
      Returns:
      两级嵌套分组(LinkedHashMap 保序)
      Since:
      1.15.0
    • addAllDistinct

      public static <T> boolean addAllDistinct(Collection<T> target, Iterable<T> source)
      原地去重合并:将 source 中 target 尚不存在的元素追加到 target 末尾(保 source 顺序)。
      Type Parameters:
      T - 元素类型
      Parameters:
      target - 目标集合(null 时不操作,返回 false)
      source - 来源可迭代对象(null 时不操作,返回 false)
      Returns:
      发生变更(有新增元素)返回 true
      Since:
      1.15.0
    • removeAll

      public static <T> boolean removeAll(Collection<T> target, Iterable<T> source)
      原地差集:从 target 中移除 source 出现的全部元素(重复元素全部移除,语义对齐 subtract(Collection, Collection))。 source 与 target 为同一对象时同样安全(内部先复制)。
      Type Parameters:
      T - 元素类型
      Parameters:
      target - 目标集合(null 时不操作,返回 false)
      source - 待移除元素来源(null 时不操作,返回 false)
      Returns:
      发生变更(有元素被移除)返回 true
      Since:
      1.15.0
    • retainAll

      public static <T> boolean retainAll(Collection<T> target, Iterable<T> source)
      原地交集:仅保留 target 中同时存在于 source 的元素(保 target 原有顺序)。
      Type Parameters:
      T - 元素类型
      Parameters:
      target - 目标集合(null 时不操作,返回 false)
      source - 保留元素来源(null 时不操作,返回 false)
      Returns:
      发生变更(有元素被移除)返回 true
      Since:
      1.15.0
    • flatten

      public static <T> List<T> flatten(Collection<? extends Collection<T>> nested)
      两级扁平化:将「集合的集合」展开为单层列表,内层 null 集合跳过。
      Type Parameters:
      T - 元素类型
      Parameters:
      nested - 嵌套集合(null 按空集合处理)
      Returns:
      扁平化后的列表(保外层与内层顺序)
      Since:
      1.15.0
    • pairwise

      public static <T> List<List<T>> pairwise(Collection<T> collection)
      相邻配对:返回相邻元素的二元组列表,长度为 size-1;少于 2 个元素时返回空列表。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 待配对集合(null 按空集合处理)
      Returns:
      相邻二元组列表(每对为不可变 List)
      Since:
      1.15.0
    • takeWhile

      public static <T> List<T> takeWhile(Collection<T> collection, Predicate<T> predicate)
      从头取满足谓词的元素前缀,遇到第一个不满足的元素即停止(Stream.takeWhile 的集合版)。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 待取集合(null 按空集合处理)
      predicate - 满足条件(null 时抛 NullPointerException)
      Returns:
      满足谓词的前缀列表(保序)
      Since:
      1.15.0
    • groupBy

      public static <T,K1,K2> Map<K1, Map<K2,List<T>>> groupBy(Collection<T> collection, Function<T,K1> key1Mapper, Function<T,K2> key2Mapper)
      双键嵌套分组(对齐 Guava Multimaps.index 多层语义)。

      按两个键依次分组为 Map<K1, Map<K2, List<T>>>,内层保序 (LinkedHashMap / ArrayList)。

      Type Parameters:
      T - 元素类型
      K1 - 第一级键类型
      K2 - 第二级键类型
      Parameters:
      collection - 待分组集合,可为 null
      key1Mapper - 第一级键提取
      key2Mapper - 第二级键提取
      Returns:
      嵌套分组 Map;null 输入返回空 Map
      Since:
      1.19.0
    • groupBy

      @SafeVarargs public static <T> Map<Object,Object> groupBy(Collection<T> collection, Function<T,?>... keyMappers)
      多键链式分组(对齐 Guava Multimaps.index)。

      按 N 个键依次嵌套分组,最内层为 List<T>;键提取器数组为空或 null 时按单键分组。

      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 待分组集合,可为 null
      keyMappers - 键提取器(可多个,变参)
      Returns:
      嵌套分组 Map;null 输入返回空 Map
      Since:
      1.19.0
    • cartesianProduct

      public static <T> List<List<T>> cartesianProduct(Collection<? extends Collection<? extends T>> collections)
      任意维度笛卡尔积(对齐 Guava Sets.cartesianProduct)。

      输入为集合的集合,每个内层集合为一个维度;任一维度为空时结果为空。

      Type Parameters:
      T - 元素类型
      Parameters:
      collections - 维度集合(外层为维度,内层为取值),可为 null
      Returns:
      笛卡尔积列表;null 返回空列表
      Since:
      1.19.0