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));

两者有区别,建议第一中,第二种会有报错,抛出异常

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