【java8】 list to map

                Map<String, String> courseNoTitleMap = listBOList.stream().collect(Collectors.toMap(CoursePriceInfoResultBO::getCourseNo, CoursePriceInfoResultBO::getTitle, (a, b) -> b));

(a, b) -> b) 的意思是,(oldValue, newValue) -> newValue),如果要put的key已存在,那麼就調用傳進來的方法。如果不指定就會拋出異常。

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