日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Stream anyMatch查找案例

發布時間:2024/9/27 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Stream anyMatch查找案例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.gblfy.gxts;import lombok.AllArgsConstructor; import lombok.Data; import org.junit.Before; import org.junit.Test;import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;/*** 案例1:* 某班集中有20名學生,每名學生有5門課的考試成績。* 其中缺考的科目分數字段為空,需要找出缺考的學生都是誰?*/ public class CaseTwo {/*** 考試成績模型*/@Data@AllArgsConstructorstatic class ExamStudentSore {/*** 考生姓名*/private String studentName;/*** 考試成績*/private Integer scoreValue;/*** 科目*/private String subject;}//初始化考試成績容器Map<String, List<ExamStudentSore>> studentMap;//初始化數據@Beforepublic void init() {//聲明考試成績容器studentMap = new HashMap<>();//張三考試成績List<ExamStudentSore> zsScoreList = new ArrayList<>();zsScoreList.add(new ExamStudentSore("張三", 80, "CHINESE"));zsScoreList.add(new ExamStudentSore("張三", 90, "MATHS"));zsScoreList.add(new ExamStudentSore("張三", 100, "ENGLISH"));zsScoreList.add(new ExamStudentSore("張三", 100, "BIOLOGICAL"));zsScoreList.add(new ExamStudentSore("張三", 80, "SPORTS"));//王五考試成績List<ExamStudentSore> wwScoreList = new ArrayList<>();wwScoreList.add(new ExamStudentSore("王五", 80, "CHINESE"));wwScoreList.add(new ExamStudentSore("王五", null, "MATHS"));wwScoreList.add(new ExamStudentSore("王五", 100, "ENGLISH"));wwScoreList.add(new ExamStudentSore("王五", 100, "BIOLOGICAL"));wwScoreList.add(new ExamStudentSore("王五", 80, "SPORTS"));//趙六考試成績List<ExamStudentSore> zlScoreList = new ArrayList<>();zlScoreList.add(new ExamStudentSore("趙六", null, "CHINESE"));zlScoreList.add(new ExamStudentSore("趙六", 90, "MATHS"));zlScoreList.add(new ExamStudentSore("趙六", 100, "ENGLISH"));zlScoreList.add(new ExamStudentSore("趙六", 100, "BIOLOGICAL"));zlScoreList.add(new ExamStudentSore("趙六", 80, "SPORTS"));//將張三、王五趙六成績放入考試成績容器studentMap.put("張三", zsScoreList);studentMap.put("王五", wwScoreList);studentMap.put("趙六", zlScoreList);}/*** 查找考試缺考的學生名單列表*/@Testpublic void findNoScoreStudentList() {studentMap.forEach((studentName, studentScoreList) -> {boolean bool = studentScoreList.stream().anyMatch(score -> {return score.getScoreValue() == null;});if (bool) {System.out.println("此學生【" + studentName + "】存在缺考的現象!");}});} }

總結

以上是生活随笔為你收集整理的Stream anyMatch查找案例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。