Java list<對象> 整個對象比較 取交集 差集


  //取差集
                    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()));
















免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM