給定一個(gè) List<User> listUser; //Userobject contains fields userName,userId, forName, last Name是否可以不用寫(xiě) 5 行來(lái)輸出用戶(hù)字段值listUser.get(0).getUserNamelistUser.get(0).getUserIdlistUser.get(0).getforName and so on 所以輸出應(yīng)該是userName -> HansuserId -> 1forName -> foolastName -> bar只需一行代碼而無(wú)需編寫(xiě) 5 行?即通過(guò)流或其他方式?listUser.stream().map(s->s.getUserName) //same as above?
Java流迭代列表最有效的方法
拉丁的傳說(shuō)
2023-09-27 16:13:26