jdk8 Stream特性

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36698213/article/details/89736245
  1. stream的filter用法

    // '#'表达式的'key值不为空'隐藏条件加在最外层 可提速
          criteriaUnit.getQueryUnitList().stream()
              .filter(queryUnit -> ESQueryUnitScope.UNIT_SCOPE_FIELDS_NOT_EQUAL.equals((queryUnit.getScope())))
              .collect(Collectors.toList())
              .forEach(filteredUnit -> boolQueryBuilder.must(new ExistsQueryBuilder(filteredUnit.getKey())));


    #在list后使用stream()方法,filter中增加过滤条件。
    #这里是相等条件。
    #collect为收集过滤后的对象集合,其中Collectors.toList() 集合变为list
    #forEach循环遍历

猜你喜欢

转载自blog.csdn.net/qq_36698213/article/details/89736245