//取差集 List<對象> differenceSet = enterpriseUserList.stream().filter(item -> !enterpriseUserPowerVos.contains(item) ).collect(Collectors.toList()); if (differenceSet.size() > 0){ baseUserMapper.addUserResource(interfaceResourceId,menuId,differenceSet,0); } //取交集 List<對象> intersection = enterpriseUserList.stream().filter(enterpriseUserPowerVos::contains ).collect(Collectors.toList());
需要注意的是 整個對象參數比較的話 需要在對應的對象上打上
@EqualsAndHashCode 標簽
List<int/string/long> 轉 map
Map<Long, Long> map = roleLists.stream().collect(Collectors.toMap(v -> v, Function.identity()));