我有一张地图如下:-
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);
});
});有更好的方法吗?
发布于 2018-10-11 13:11:47
您可以为第二个forEach使用一个方法引用,并且您正在执行一个不必要的mapList.get --您已经有了这个值。
forEach((k, v) -> {
System.out.println("URL" + k);
v.forEach(System.out::print);
});发布于 2018-10-11 13:11:49
我认为你在寻找:
mapList.forEach((k, v) -> System.out.println("URL " + k + ", values : " + v)));它将输出以下内容:
URL http://url1,值: a,b URL http://url2,值: c,d
https://stackoverflow.com/questions/52760832
复制相似问题