【java8】java8取出list中的对象的某一属性

public class UserEntity implements Serializable {
    
    private Integer id;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 用户手机号
     */
    private String phone;
}


public static void main(string args[]){
    
    List users=new ArrayList<>();

    users.add(new UserEntity(1,"张三","18399990000"));
    users.add(new UserEntity(2,"王五","18399990023"));
    users.add(new UserEntity(3,"里斯","18399990005"));

List courseIds=  users.stream().map(UserEntity::getUserName).collect(Collectors.toList());
}

最终的结果是

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