java - bean collection split into multiple lists
迷茫
迷茫 2017-05-17 10:08:35
0
2
786

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 = ...
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
我想大声告诉你
List<String> name = data.stream().map(User::getName).collect(Collectors.toList());
List<String> age = data.stream().map(User::getAge).collect(Collectors.toList());
Ty80

Map<String,User> should satisfy you. The key is name and the value is placed directly in the bean

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!