好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

java Match如何使用

概念

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的使用,希望对大家有所帮助。 更多编程基础知识学 习: python学习网

本教程操作环境:windows7系统、java10版,DELL G3电脑。

查看更多关于java Match如何使用的详细内容...

  阅读:30次