Search code examples
javadictionaryentryset

How do i extract the length of integer array from Map<int , int[] >?


How do i extract the length of integer array from a `Map?

Map <Integer, ArrayList<Integer>> res = function() ;

for (Map.Entry entry : res.entrySet()) {
  System.out.println(entry.getValue());        
}   

Doing System.out.println(entry.getValue().size()); does not work.


Solution

  • You need to specify type arguments for your Entry.

    for(Map.Entry<Integer, ArrayList<Integer>> entry : res.entrySet()){
    

    Otherwise, the type usage is raw.

    See