流式计算

1.什么是流式计算

大数据 = 存储 + 计算
存储:map 、mysql 等
计算:交给流来计算

2.举例

  • lambda表达式、链式编程、函数式接口、Stream流式计算
public class StreamDemo {

    public static void main(String[] args) {
        User user1 = new User(1,"a",21);
        User user2 = new User(2,"b",22);
        User user3 = new User(3,"c",23);
        User user4 = new User(4,"d",24);
        User user5 = new User(5,"e",25);
        User user6 = new User(6,"f",26);

        List<User> list = Arrays.asList(user1,user2,user3,user4,user5,user6);

                //计算交给流
                //lambda表达式、链式编程、函数式接口、Stream流式计算
                list.stream()
                .filter(u->{return u.getId()%2==0;})//过滤掉id为二的
                .filter(u->{return u.getAge()>22;})//过滤年龄小于22的
                .map(u->{return u.getName().toUpperCase();})//名字转大写
                .sorted((uu1,uu2)->{return uu2.compareTo(uu1);})//用户名倒着排序
                .limit(1) //限制输出一个
                .forEach(System.out::println);
    }
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
    private int id;
    private String name;
    private int age;

}

你可能感兴趣的:(JDK特性)