Now there is a bean list that needs to be split into multiple member lists. How to write it better?
public class User {
private String name;
private String age;
//..getter,settter省略
}
List<User> data = ...
List<String> name = data里的所有name
List<String> age = ...
我想大声告诉你2017-05-17 10:10:35
List<String> name = data.stream().map(User::getName).collect(Collectors.toList());
List<String> age = data.stream().map(User::getAge).collect(Collectors.toList());
PHP中文网2017-05-17 10:10:35
Map<String,User> should satisfy you. The key is name and the value is placed directly in the bean