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查找案例相关推荐

  1. java anymatch_Java Stream anyMatch() API

    Java Stream anyMatch(谓词谓词)是终端短路操作,用于检查流中是否包含具有提供的predicate任何匹配元素. 1. Stream anyMatch() method 1.1. S ...

  2. java8 .stream().anyMatch / allMatch / noneMatch用法

    java8 stream接口终端操作 anyMatch,allMatch,noneMatch anyMatch:判断的条件里,任意一个元素成功,返回true allMatch:判断条件里的元素,所有的 ...

  3. Stream filter过滤案例

    package com.gblfy.gxts;import com.google.common.collect.Lists; import lombok.AllArgsConstructor; imp ...

  4. Java Stream流综合案例

    综合案例: 现在有两个ArrayList集合存储队伍当中的多个成员姓名,要求使用传统的for循环(或堵强for循环)和stream流依次进行以下若干操作步骤; 1.第一个队伍只要名字为3个字的成员姓名 ...

  5. excel 多条件查找三种方法:lookup、vlookup、indexmatch 多条件查找案例

    最近在Excel微信学习交流群中收到某位学员的问题咨询,问题是如何返回单据编号和物料长代码对应的含税数额.如下表: 其实这位学员的问题就是excel的多条件查找问题. 下面通过一个实例跟大家分享一下常 ...

  6. C++基础-字符串的排序与查找案例(查找姓名位置)

    将若干个姓名按照字典序重新排列,然后从中找一个名字,输出所在位置. #include <iostream> using namespace std; #include <cstrin ...

  7. java stream findlast_恕我直言你可能真的不会java第9篇-Stream元素的匹配与查找

    在我们对数组或者集合类进行操作的时候,经常会遇到这样的需求,比如: 是否包含某一个"匹配规则"的元素 是否所有的元素都符合某一个"匹配规则" 是否所有元素都不符 ...

  8. Java 8 stream forEach filter anyMatch

    forEach的循 someObjects.forEach(obj -> { //to do something }) 如果这个循环的目标是找到匹配某个谓词的第一个元素 Optional< ...

  9. java8 stream案例分析

    java8 stream Stream是java8 推出的一个处理集合类的一个全新的接口,在工作当中经常用到,并且他的预发规则与我们平台的有一点不一样,是流式的处理,非常类似RXJava的一个风格. ...

最新文章

  1. js获取网页的各种高度
  2. 反射学习笔记之动态创建对象和调用方法
  3. 从员工出走仅剩 5 人,到一支打胜仗的铁军
  4. 【C语言实现反转数组】(用栈实现)51nod - 训练营
  5. Elasticsearch 的使用,看这一篇就够了!
  6. uniapp图标_uniapp扩展自定义uniIcon组件图标
  7. icd植入是大手术吗_母狗绝育是大手术吗?手术完需要住院吗?绝育后是不是会变胖?...
  8. 并发之AtomicIntegerFieldUpdater
  9. border-radius的8个属性值_画半圆、叶子等
  10. php程序员开发工具箱,PHP程序员工具箱免费版
  11. SageMath常用函数
  12. 程序员,如何做好工作复盘?
  13. 如何打断制图中的CAD图形?
  14. Golang操作阿里云OSS上传文件
  15. wso2_围绕开放标准改进WSO2 API Manager密钥管理体系结构
  16. .NET WebAPI 微信网页授权的实现(一)前端篇
  17. 2016年关总结 让爱更有力量
  18. 【数据结构】B/B-树(目录树)
  19. Exchange Server 2016 RTM快速部署指南
  20. 开发新闻类APP需要准备什么

热门文章

  1. 2019世界大学排名全新出炉!清华北大排名大幅下滑?
  2. 美国著名核物理学家,前半生为美国造核弹,后半生为中国放牛
  3. 雷军99亿人民币薪酬创世界纪录,相当于100个库克
  4. 数学家眼里的相同与不同
  5. 费尔马小定理素数java_利用费马小定理判断素数
  6. mysql中count(*),count(字段),count(1)的区别
  7. C++ vector用法
  8. Java对象转换方案分析与mapstruct实践
  9. 刚刚,阿里开源 iOS 协程开发框架 coobjc!
  10. 深入Spring Boot:利用Arthas排查NoSuchMethodError