【发布时间】:2021-07-16 20:16:52
【问题描述】:
这是我的代码:
List<String[]> salaries = getSalariesByMonth();
//I am using the old way to print the data
for (String[] obj : rates) {
System.out.println("User name: "obj[0]+"--"+"Salary: "+obj[1]); //obj[0] is NAME, obj[1] is SALARY
}
//I am trying to use this way to print the data but unable to do so.
salaries.forEach(s-> System.out.println("print NAME and SALARY"));
如何使用 Lambda 打印包含字符串数组的列表。提前谢谢你。
【问题讨论】:
-
嗯,是什么阻碍了你的 lambda?你尝试了什么?什么不工作?
-
我正在尝试在 lambda 中使用 r[0], r[1] 但它不起作用。不知道如何从 r 中获取数据。