java8取出list中的对象的某一属性
public class UserEntity implements Serializable {
private Integer id;
/**
* 用户名
*/
private String userName;
/**
* 用户手机号
*/
private String phone;
}
public static void main(string args[]){
List<UserEntity> users=new ArrayList<>();
users.add(new UserEntity(1,"张三","18399990000"));
users.add(new UserEntity(2,"王五","18399990023"));
users.add(new UserEntity(3,"里斯","18399990005"));
List<String> courseIds= users.stream().map(UserEntity::getUserName).collect(Collectors.toList());
}
最终的结果:[张三,王五,里斯]