现在有个bean的list,需要拆成多个成员的list,怎么写比较好?
public class User {
private String name;
private String age;
//..getter,settter省略
}
List<User> data = ...
List<String> name = data里的所有name
List<String> age = ...
3 回答
呼如林
TA贡献1798条经验 获得超3个赞
List<String> name = data.stream().map(User::getName).collect(Collectors.toList());
List<String> age = data.stream().map(User::getAge).collect(Collectors.toList());
添加回答
举报
0/150
提交
取消