java8根據list某一屬性去重

//根據id去重
examRoomModelLists = examRoomModelLists.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
                // 利用 TreeSet 的排序去重構造函數來達到去重元素的目的
                // 根據firstName去重
                () -> new TreeSet<>(Comparator.comparing(ExamRoomModel::getId))), ArrayList::new));

 

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