从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 @ 2023-01-07 13:33  了悟  阅读(674)  评论(0编辑  收藏  举报