我有一张如下图:-
HashMap<String, Set<String>> mapList;
我正在检索如下数据:-
mapList.forEach((k, v) -> {
System.out.println("URL" + k);
Set<String> s = mapList.get(k);
s.forEach(e -> {
System.out.print(e);
});
});
有更好的方法吗?
最佳答案
您可以对第二个 forEach
使用方法引用,而您正在执行不必要的 mapList.get
- 您已经有了值。
forEach((k, v) -> {
System.out.println("URL" + k);
v.forEach(System.out::print);
});
关于java - 从 map 中检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52760832/