lambda 表達式常用

獲取對象屬性id爲key,值爲當前對象

List<BatchLibraryRule> genRules = libraryRule.getRules();
                Map<Integer,BatchLibraryRule> categoryRuleMap = null;
                if(CollectionUtils.isNotEmpty(genRules)) {
                    categoryRuleMap = genRules.stream().collect(Collectors.toMap(BatchLibraryRule::getRuleCategory,g -> g));
                }else {
                    genRules = new ArrayList<>();
                    categoryRuleMap = new HashMap<>();
                }

 

獲取集合的對象的某列組成新的集合

    List<BatchInventory> allInventorys = batchInventoryDao.findBatchInventorysByJobId(jobId);
        Set<Integer> inventoryIds = allInventorys.stream().map(BatchInventory::getId).collect(Collectors.toSet());

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章