0
点赞
收藏
分享

微信扫一扫

Java8-Stream流(最终操作)matching

allMatch: 只有当流中所有的元素,都匹配指定的规则,才会返回 true
anyMatch: 只要流中有任意的数据,满足指定的规则,都会返回 true
noneMatch: 只有当流中的所有的元素,都不满足指定的规则,才会返回true

package Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @Author yqq
* @Date 2021/10/17 13:40
* @Version 1.0
*/
public class demo01 {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
Collections.addAll(list,0,1,2,3,4,5,6,7,8,9);
System.out.println(list);
boolean b = list.stream().allMatch(e -> e>=0);//false
boolean c = list.stream().anyMatch(e -> e>8);//true
boolean d = list.stream().noneMatch(e -> e>9);//true
System.out.println(d);
}
}


举报

相关推荐

0 条评论