利用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