从list列表中获取某字段列表

复制代码
List<User> userList = new ArrayList<>();
//list集合中获取code集合
List<String> codeList = userList.stream().map(i -> i.getCode()).collect(Collectors.toList());
//
List<String> codeList = userList.stream().map(User::getCode).collect(Collectors.toList());
//
List<String> codeList = new ArrayList<>();
for (User user : userList) {
    codeList.add(user.getCode());
}
复制代码

 

posted @   了悟  阅读(702)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示