Methods for dealing with collections
- CollectionUtils.union(list1,list2): returns the union of two lists
Example:def list1 = ["A", "B", "C", "D", "E", "F"] def list2 = ["B", "D", "F", "G", "H", "K"] def re = CollectionUtils. union(list1, list2) log. info(re) // [A, B, C, D, E, F, G, H, K]
- CollectionUtils.intersection(list1,list2): returns the intersection of two lists
Example:def list1 = ["A", "B", "C", "D", "E", "F"] def list2 = ["B", "D", "F", "G", "H", "K"] def re = CollectionUtils. intersection(list1, list2) log. info(re) //[B, D, F]
- CollectionUtils.disjunction(list1,list2): returns the complement of the intersection of two lists (disjunction)
Example:def list1 = ["A", "B", "C", "D", "E", "F"] def list2 = ["B", "D", "F", "G", "H", "K"] def re = CollectionUtils.disjunction(list1, list2) log.info(re) //[A, C, E, G, H, K]
- CollectionUtils.subtract(list1,list2): returns the difference (subtraction) of two lists
Example:def list1 = ["A", "B", "C", "D", "E", "F"] def list2 = ["B", "D", "F", "G", "H", "K"] def re = CollectionUtils. subtract(list1, list2) log.info(re) //[A, C, E]
- CollectionUtils.isEqualCollection(list1,list2): Determine whether two collections are equal
Example:def list1 = ["A", "B", "C", "D", "E", "F"] def list2 = ["A", "F", "B", "C", "D", "E"] def re = CollectionUtils.isEqualCollection(list1, list2) log. info(re) //true
- CollectionUtils.isSubCollection(list1,list2): Whether list1 is a subset of list2
Example:def list1 = ["A", "F"] def list2 = ["A", "B", "C", "D", "E", "F"] def re = CollectionUtils.isSubCollection(list1, list2) log. info(re) //true
- CollectionUtils.cardinality(str,list1): the number of occurrences of the element
Example:def list1 = ["A", "A", "A", "D", "E", "F"] String str = "A" def re = CollectionUtils. cardinality(str, list1) log. info(re) //3