package stream; import java.util.Arrays; import java.util.List; /** * @author zzl * @Date 2022/1/15 * @description Java stream特性 */ public class StreamTest { public static void main(String[] args) { List<String> resultList = Arrays.asList("a", "b", "c"); // allMatch:判断集合中的所有元素都是满足条件,返回true boolean allMatch = resultList.stream().allMatch(param -> param.equals("a")); // anyMatch:判断集合中的其中一个元素满足条件,返回true boolean anyMatch =resultList.stream().anyMatch(param->param.equals("a")); // noneMatch:判断集合中的所有元素都不满足条件,返回true boolean noneMatch =resultList.stream().noneMatch(param->param.equals("a")); System.out.println("allMatch="+allMatch); System.out.println("anyMatch="+anyMatch); System.out.println("noneMatch="+noneMatch); } }
执行结果:
allMatch=false anyMatch=true noneMatch=false