java Match怎么使用

王林
王林 转载
2023-04-18 13:55:03 883浏览

概念

1、各种Match操作可用于判断给定的Predicate是否符合Stream的要素。

2、Match操作是终端操作,返回布尔值。

实例

boolean anyStartsWithA =
    stringCollection
        .stream()
        .anyMatch((s) -> s.startsWith("a"));
 
System.out.println(anyStartsWithA);      // true
 
boolean allStartsWithA =
    stringCollection
        .stream()
        .allMatch((s) -> s.startsWith("a"));
 
System.out.println(allStartsWithA);      // false
 
boolean noneStartsWithZ =
    stringCollection
        .stream()
        .noneMatch((s) -> s.startsWith("z"));
 
System.out.println(noneStartsWithZ);      // true

以上就是java Match怎么使用的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:亿速云,如有侵犯,请联系admin@php.cn删除