{// 集合判空 List<Integer> list = new ArrayList<>(); list.add(2); list.add(1); list.add(3); if (CollectionUtils.isEmpty(list)) { System.out.println("集合为空"); } if (CollectionUtils.isNotEmpty(list)) { System.out.println("集合不为空"); } } {// 对两个集合进行操作 List<Integer> list = new ArrayList<>(); list.add(2); list.add(1); list.add(3); List<Integer> list2 = new ArrayList<>(); list2.add(2); list2.add(4); //获取并集 Collection<Integer> unionList = CollectionUtils.union(list, list2); System.out.println(unionList); //获取交集 Collection<Integer> intersectionList = CollectionUtils.intersection(list, list2); System.out.println(intersectionList); //获取交集的补集 Collection<Integer> disjunctionList = CollectionUtils.disjunction(list, list2); System.out.println(disjunctionList); //获取差集 Collection<Integer> subtractList = CollectionUtils.subtract(list, list2); System.out.println(subtractList); }
标签:CollectionUtils,list,System,list2,add,apache,org,out From: https://www.cnblogs.com/ooo0/p/17750675.html