bean集合拆分成多个list

现在有个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 = ...
慕容708150
浏览 654回答 3
3回答

呼如林

List<String> name = data.stream().map(User::getName).collect(Collectors.toList()); List<String> age = data.stream().map(User::getAge).collect(Collectors.toList());
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java