java8stream获得List对象中某⼀属性重新⽣成List public class User implements Serializable {
private Integer id;
private String name;
private BigDecimal price;
public Integer getId(){
return id;
}
public void setId(Integer id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public BigDecimal getPrice(){
return price;
}
public void setPrice(BigDecimal price){
this.price = price;
}
}
List<User>list=new ArrayList<>();
User user1=new User();
user1.setId(1);
user1.setName("李四");
User user2=new User();
user2.setId(2);
user2.setName("王五");
bigdecimal转换为integerlist.add(user1);
list.add(user2);
List<Integer> collect = list.stream().map(User::getId).List());
System.out.println(collect);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论