Java 8 Stream

Map<Long, AreaInfo> cityCollect = list.stream().collect(Collectors.toMap(AreaInfo::getCityId, po -> po, (key, key2) -> key2));
Map<Long, AreaInfo> cityCollect = list.stream().collect(Collectors.toMap(AreaInfo::getCityId, po -> po));

兩者有區別,建議第一中,第二種會有報錯,拋出異常

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