给定一个
List<User> listUser; //Userobject contains fields userName,userId, forName, last Name
是否可以不用写 5 行来输出用户字段值
listUser.get(0).getUserName
listUser.get(0).getUserId
listUser.get(0).getforName and so on
所以输出应该是
userName -> Hans
userId -> 1
forName -> foo
lastName -> bar
只需一行代码而无需编写 5 行?即通过流或其他方式?
listUser.stream().map(s->s.getUserName) //same as above?
慕哥6287543
相关分类