Lamada学习总结
1、新建实体类Car(省略set/get/构造方法/toString())
private Integer id;
private String color;
private Double price;
private String name;
2、初始化一个List<Car>
List<Car> carList=new ArrayList<>();
for(int i=0;i<=5;i++){
Car car=new Car(i,"黄色"+i,125.23+23.5*i,"奥迪"+i);
carList.add(car);
}
System.out.println("初始化:"+carList);
3、提取某一个属性
//提取某一列属性
List<Integer> collect = carList.stream().map(o -> o.getId()).collect(Collectors.toList());
System.out.println(collect);
4、加入特殊数据(需要用lamada处理的某一个属性为空)
//属性列为空
Car car=new Car(null,"黄色"+6,125.23+23.5*6,"奥迪"+6);
carList.add(car);