lambda表达式之allMatch、anyMatch、noneMatch

2022年6月7日09:46:11

  allMatchStream中全部元素符合传入的predicate返回 true

  anyMatchStream中只要有一个元素符合传入的predicate返回 true

  noneMatchStream中没有一个元素符合传入的predicate返回 true

  List<String> list = new ArrayList<String>();
  list.add("one");
  list.add("two");
  list.add("three");
  list.add("four");
  list.add("five");



  Boolean bl = list.stream().anyMatch(x->x.length()==4);
  System.out.println(bl);
    打印true
            boolean anyMatch = catList.stream().parallel().noneMatch(e -> e.getId().equals(newArticleBO.getCategoryId()));
            if (anyMatch) {
                return R.en(ResultEnum.ARTICLE_CATEGORY_NOT_EXIST_ERROR);
            }
  • 作者:努力奋斗GO
  • 原文链接:https://blog.csdn.net/qq_39940205/article/details/114106896
    更新时间:2022年6月7日09:46:11 ,共 527 字。