stream流——anyMatch用法

介绍
只要有一个满足条件,返回true
代码


import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Person {
    private int id;
    private String name;
    private int age;
}

    public static void main(String[] args) {
        Person p1 = new Person(1, "A", 10);
        Person p2 = new Person(2, "B", 12);
        Person p3 = new Person(3, "C", 14);
        Person p4 = new Person(4, "D", 12);
        List<Person> list = Arrays.asList(p1, p2, p3, p4);
        // list中有年龄大于13的返回true
        boolean flag = list.stream().anyMatch(item -> item.getAge() > 13);
        System.out.println(flag);
    }

你可能感兴趣的:(学习记录,java,开发语言)