我有一个很长的 Map (int, int[] ) ;
我使用 map.entrySet() 并返回我的 map 的 Set View
Map <Integer, ArrayList<Integer>>res = function() ;
System.out.println( res.entrySet() ) ;
我想在新行中显示每个条目:
[1=[1, 47, 432, 433, 527, 678, 679, 680, 820, 904],
2=[1, 31, 47, 66, 118, 139, 194, 195, 196, 217]
3 = [............],
10 = [............],
但是我把它全部打印在一行上(它很长):
[1=[1, 47, 432, 433, 527, 678, 679, 680, 820, 904], 2=[1, 31, 47, 66, 118, 139, 194, 195, 196, 217 ], 3=[123,23,.......],.......
如何让我的集合在新行上打印每个键值对? 还是在逗号之后并在一行中默认使用逗号?
最佳答案
只需遍历 Map
的 EntrySet
并打印
for(Map.Entry entry : res.entrySet()){
System.out.println(entry);
//System.out.println(entry.getKey() + "=[" + entry.getValue() + "]");
}
关于java - 如何让 entrySet() 在新行显示键值对?(java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22436597/