码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【JDK 8-集合框架】5.4 allMatch 和 anyMatch 函数


    一、allMatch 函数

    二、anyMatch 函数

    三、其它函数学习

    四、实战

    > 执行结果


    一、allMatch 函数

    • 检查是否 匹配所有元素,返回 true

    二、anyMatch 函数

    • 检查是否 至少匹配一个元素,返回 true

    三、其它函数学习

    • 看源码 + 入参,返回值 学习

    • 如 noneMatch

    1. /**
    2. * Returns whether no elements of this stream match the provided predicate.
    3. * May not evaluate the predicate on all elements if not necessary for
    4. * determining the result. If the stream is empty then {@code true} is
    5. * returned and the predicate is not evaluated.
    6. *
    7. *

      This is a short-circuiting

    8. * terminal operation.
    9. *
    10. * @apiNote
    11. * This method evaluates the universal quantification of the
    12. * negated predicate over the elements of the stream (for all x ~P(x)). If
    13. * the stream is empty, the quantification is said to be vacuously satisfied
    14. * and is always {@code true}, regardless of P(x).
    15. *
    16. * @param predicate a non-interfering,
    17. * stateless
    18. * predicate to apply to elements of this stream
    19. * @return {@code true} if either no elements of the stream match the
    20. * provided predicate or the stream is empty, otherwise {@code false}
    21. */
    22. boolean noneMatch(Predicatesuper T> predicate);

    四、实战

    1. import java.util.Arrays;
    2. import java.util.List;
    3. public class MatchDemo {
    4. public static void main(String[] args) {
    5. List list = Arrays.asList("Spring Boot", "Python", "微服务", "高并发", "Redis", "MongoDB");
    6. boolean result = list.stream()
    7. .allMatch(obj -> obj.length() > 7);
    8. System.out.println(">> allMatch() :全匹配长度大于7");
    9. System.out.println(result + "\n");
    10. result = list.stream()
    11. .anyMatch(obj -> obj.length() > 1);
    12. System.out.println(">> anyMatch() :部分匹配长度大于7");
    13. System.out.println(result + "\n");
    14. result = list.stream()
    15. .noneMatch(obj -> obj.length() > 20);
    16. System.out.println(">> noneMatch() :没有一个匹配长度大于20");
    17. System.out.println(result + "\n");
    18. }
    19. }

    > 执行结果

  • 相关阅读:
    笔试强训Day8
    科技部首批支持建设十个人工智能示范应用场景,智能家居再获加持
    java-php-python-ssm学生在线评教系统计算机毕业设计
    计算机毕设(附源码)JAVA-SSM基于JAVA语言的宠物寄养管理
    23种设计模式(十三)组合模式(阁瑞钛伦特软件-九耶实训)
    设计模式:代理模式详解
    Stable Diffusion半秒出图;VLIW的前世今生;YOLOv5全面解析教程 | AI系统前沿动态
    ArcGIS水文分析工具
    七、鼎捷T100采购应付管理流程
    解决Maven导入坐标 Cannot resolve Failure to transfer 报错问题
  • 原文地址:https://blog.csdn.net/ladymorgana/article/details/133035354
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号