如何让entrySet()在新行显示键值对?(java)

ERJ*_*JAN 2 java dictionary hashmap set entryset

我有一个很长的 Map (int, int[] ) ;

我使用map.entrySet(),它返回我的地图的设置视图

Map <Integer, ArrayList<Integer>>res = function() ;
    System.out.println( res.entrySet() ) ;
Run Code Online (Sandbox Code Playgroud)

我想在新行上显示每个条目:

[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,……],…………

如何让我的设置在新行上打印每个键值对? 或者默认情况下逗号在逗号之后并且在一行中?

Ani*_*kur 6

只需迭代并EntrySet打印Map

    for(Map.Entry entry : res.entrySet()){
        System.out.println(entry);
        //System.out.println(entry.getKey() + "=[" + entry.getValue() + "]");
    }
Run Code Online (Sandbox Code Playgroud)