首页 > 其他分享 >从list列表中获取某字段列表

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

时间:2023-01-07 13:46:05浏览次数:48  
标签:某字段 getCode list List 列表 userList codeList

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

 

标签:某字段,getCode,list,List,列表,userList,codeList
From: https://www.cnblogs.com/onlyzhangmeng/p/17032521.html

相关文章