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