List数据处理
1)获取并集
Collection unionList = CollectionUtils.union(list, list2); System.out.println(unionList);
2)获取交集
Collection intersectionList = CollectionUtils.intersection(list, list2); System.out.println(intersectionList);
3)获取交集的补集
Collection disjunctionList = CollectionUtils.disjunction(list, list2); System.out.println(disjunctionList);
4)获取差集 Collection
subtractList = CollectionUtils.subtract(list, list2);
System.out.println(subtractList);
5)笛卡尔积
如果你想将两个集合做笛卡尔积,Lists的cartesianProduct方法可以帮你实现:
List list1 = Lists.newArrayList(1, 2, 3);
List list2 = Lists.newArrayList(4,5);
List<List> productList = Lists.cartesianProduct(list1,list2);
System.out.println(productList);
执行结果:[[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]
6)分页
如果你想将一个大集合分成若干个小集合,可以使用Lists的partition方法:
List list = Lists.newArrayList(1, 2, 3, 4, 5);
List<List> partitionList = Lists.partition(list, 2);
System.out.println(partitionList);
执行结果:[[1, 2], [3, 4], [5]]
7)list
//倒叙
list.sort(Comparator.comparing((Map<String, Object> h) ->
((String) h.get(“DY”))).reversed());
8)list <实体类排序>
list=list.stream().sorted(Comparator.comparing(FiAccount::getRealPayDate)).collect(Collectors.toList());//ASC
list=list.stream().sorted(Comparator.comparing(FiAccount::getRealPayDate).reversed()).collect(Collectors.toList());//DESC
9)list分组
Map<String,List<Map<String,Object>>> bpmNameMap = mapList.stream().collect
(Collectors.groupingBy(map->map.get(“bpmName”).toString()));
10)判断两个对象是否相等
boolean bool = Objects.equels(obj1,obj2);