0
点赞
收藏
分享

微信扫一扫

List<对象> 取其中的某个属性 List<id>


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());
}


举报

相关推荐

0 条评论