/**
* 取出所有的用户名字
* 学会建立临时的数据转换和数据存储的掌握
*/
public static void getUserNameList() {
List<PersonModel> data = Data.getData();
//jdk1.7
List<String> list = new ArrayList<>();
for (PersonModel persion : data) {
list.add(persion.getName());
}
//jdk1.8 1
List<String> list1 = data.stream()
.map(PersonModel::getName)
.collect(Collectors.toList());
//有body一定有return
data.stream()
.map(personModel -> {
return personModel.getName(); //将返回的值放入到集合中;
})
.collect(Collectors.toList());
}
相关文章: