取出list对象中的某一属性值

时间:2025-04-25 07:00:01
public class Store implements Serializable { private Integer id; private String userName; private String phone; } public static void main(string args[]){ List<Store> users=new ArrayList<>(); users.add(new Store(1,"张三","18399990000")); users.add(new Store(2,"王五","18399990023")); users.add(new Store(3,"里斯","18399990005")); List<String> courseIds= users.stream().map(Store::getUserName).collect(Collectors.toList()); }```