處理集合相關(guān)的方法
CollectionUtils.union(list1,list2): 返回兩個list去的并集
舉例:
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): 返回兩個list的交集
舉例:
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): 返回兩個list的交集的補(bǔ)集(析?。?br style="box-sizing: border-box; border-width: 0px; border-style: solid; border-color: rgba(229,231,235,var(--tw-border-opacity)); border-image: initial; --tw-border-opacity: 1; --tw-shadow: 0 0 transparent; --tw-ring-inset: var(--tw-empty,/*!*/ /*!*/); --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(59,130,246,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent;"/>舉例:
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): 返回兩個list的差集(扣除)
舉例:
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): 判斷兩個集合是否相等
舉例:
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): list1是否為list2的子集
舉例:
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): 元素出現(xiàn)的次數(shù)
舉例:
def list1 = ["A", "A", "A", "D", "E", "F"] String str = "A" def re = CollectionUtils.cardinality(str, list1) log.info(re) //3部分內(nèi)容來源于互聯(lián)網(wǎng),如有侵權(quán),請聯(lián)系客服刪除處理。