链式编程+流式计算 一个小题目

package main.test;
import	java.util.Arrays;
import	java.util.List;

/**
 * @Auther: wdq
 * @Date: 2020/4/21 15:44
 * @Description:筛选出编号偶数并且年龄大于25的人,要求把名字大写并逆序输出第一个人。
 */
class User{
    private String name;
    private int id;
    private int age;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public User() {
    }
    public User(int id, String name, int age) {
        this.name = name;
        this.id = id;
        this.age = age;
    }
}

public class StreamDemo {
    public static void main(String[] args) {
        User u1 = new User(11,"a",23);
        User u2 = new User(12,"b",24);
        User u3 = new User(13,"c",22);
        User u4 = new User(14,"d",28);
        User u5 = new User(16,"e",26);
        List users =Arrays.asList(u1,u2,u3,u4,u5);

        users.stream().filter(u -> u.getId()%2==0)
                .filter(u -> u.getAge() > 25)
                .map(u->u.getName().toUpperCase())
                .sorted((a,b)->b.compareTo(a))
                .limit(1)
                .forEach(System.out::println);
    }
}
/*
E
*/

 

你可能感兴趣的:(JAVA面试题,JAVA线程编程)