利用jdk 1.8新特性遍歷List進行分類


List<NoteDesc> noteDescs = null; Map<String, Object> maps = new HashMap<>(); List<NoteDesc> descs = noteDescDao.findAll(); // 根據noteId去重 List<NoteDesc> lists = descs.stream().collect(collectingAndThen(toCollection(() -> new TreeSet<>(Comparator.comparing(NoteDesc::getNoteID))), ArrayList::new)); for (NoteDesc noteDesc : lists) { noteDescs = new ArrayList<>(); for (NoteDesc desc : descs) { if(noteDesc.getNoteID() == desc.getNoteID()) { noteDescs.add(desc); } } maps.put(noteDesc.getNoteName(), noteDescs); } return maps;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM