8.Stream流式计算
/**
* 链式编程的写法:
* 如何用一行代码实现:
* 1.ID必须是偶数
* 2.年龄必须大于23
* 3.用户名转为大写字母
* 4.用户名字母倒序
* 5.只输出一个用户
*/
public class Test {
public static void main(String[] args) {
User u1 = new User(1,"a",21);
User u2 = new User(2,"b",22);
User u3 = new User(3,"d",23);
User u4 = new User(4,"e",24);
User u5 = new User(5,"f",25);
//重点1:集合就是存储,转为list集合
List<User> list= Arrays.asList(u1,u2, u3, u4, u5);
//重点2:list.stream()转为stream流
list.stream()
.filter(u->{return u.getId()%2==0;})
.filter(u->{return u.getAge()>23;})
.map(u->{return u.getName().toUpperCase();})
.sorted((uu1,uu2)->{return uu1.compareTo(uu2);})
.limit(1)
.forEach(System.out::println);
}
}