暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Java新特性解读JDK8之流操作allMatch和anyMatch函数

227decision 2020-02-03
5046

allMatch函数

作用:Returns whether all elements of this stream match the provided predicate. 即判断是否所有的元素都匹配检查条件。

allMatch使用,代码如下:

    package com.example.streamdemo;


    import java.util.Arrays;
    import java.util.List;


    public class AnyMatchDemo {
    public static void main(String[] args) {
    List<String> list = Arrays.asList("java","c","Python");
    boolean anyMatch = list.stream().anyMatch(obj->obj.endsWith("a"));
    System.out.println(anyMatch);
        }
    }
    复制

    anyMatch函数

    作用:Returns whether any elements of this stream match the provided. 即判断是否至少有一个元素匹配检查条件。

    anyMatch使用,代码如下:

      package com.example.streamdemo;


      import java.util.Arrays;
      import java.util.List;


      public class AnyMatchDemo {
      public static void main(String[] args) {
      List<String> list = Arrays.asList("java","c","Python");
      boolean anyMatch = list.stream().anyMatch(obj->obj.endsWith("a"));
      System.out.println(anyMatch);
          }
      }
      复制


      最后修改时间:2020-07-01 13:35:48
      文章转载自227decision,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

      评论