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());