javadictionaryhashmapsetentryset

How to make entrySet() show key-value pairs on new line?(java)


I have a long Map (int, int[] ) ;

I use map.entrySet() and it returns me the Set view of my map

Map <Integer, ArrayList<Integer>>res = function() ;
    System.out.println( res.entrySet() ) ;

i want to show every entry on new line:

[1=[1, 47, 432, 433, 527, 678, 679, 680, 820, 904],

2=[1, 31, 47, 66, 118, 139, 194, 195, 196, 217]

3 = [.............],

10 = [..............],

but instead i have it all printed on one line(it's very long):

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

How to make my set print each key-value pair on new line? or is it by default comma after comma and in one line?


Solution

  • Just iterate over the EntrySet of the Map and print

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