流式数据处理是java8的新特效之一,流处理在加上lambda表达式极大的提高编程效率和程序可读性。
创建一个实体类
public class User {
private Integer id ;
private String name ;
private String sex;
private Integer age;
private BigDecimal weight;
public void setId(Integer id){
this.id = id;
}
public Integer getId(){
return this.id;
}
public void setSex(String sex){
this.sex= sex;
}
public String getSex(){
return this.sex;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setAge(Integer age){
this.age = age
}
public Integer getAge(){
return this.age;
}
public void setWeight(String weight){
this.weight = weight;
}
public String getWeight(){
return this.weight;
}
对list进行操作
// stream().forEach()遍历集合
list.stream().forEach(user->{
System.out.println(user