Iterate over a hashmap using a recordset

for (Map.Entry<String, Map<String, List>> entry:Map1.entrySet()) { String key=entry.getKey(); System.out.println("Type : " +key); for (Map.Entry<String, List> entry1 : entry.getKey().getValue().entrySet()) { System.out.println("Type : " + entry1.getKey()); } } 

I do not know what should be used instead of entry.getKey().getValue().entrySet() . Can someone explain to me to understand this. This is for iterating a nested map.

i got an error

 .\common\devtracker\process\devtr\DevTrackerImpl.java:226: cannot find symbol symbol : method getValue() location: class java.lang.String for (Map.Entry<String, List<ProjectBreakupVO>> entry1:entry.getKey().getValue().entrySet()) 
+4
source share
3 answers

entry.getKey () does not have a getValue () method, because it just returns a string. What you probably want here.

 for (Map.Entry<String, List> entry1 : entry.getKey().getValue().entrySet()) 

do instead

 for (Map.Entry<String, List> entry1 : entry.getValue().entrySet()) 
+2
source

You must use ....

 for (Map.Entry<String, List> entry1 : entry.getKey().getValue().entrySet()) 

to get records for the inner loop.

0
source

If you are trying to iterate over a map like Map<String, List> , and you encounter findbugs problems when using myMap.keySet() as follows:

  for (String keyValue : myMap.keySet()) { String key = keyValue; List objValue = myMap.get(key); } 

then try iterating over the map using myMap.entrySet() , which is more recommended:

  for(Map.Entry<String, List> entry: myMap.entrySet()) { String key = entry.getKey(); List objValue = entry.getValue(); } 

Thus, forloop nesting in this case will look like this:

 for (Map.Entry<String, Map<String, List>> entry:Map1.entrySet()) { String key=entry.getKey(); System.out.println("Type : " +key); for (Map.Entry<String, List> entry1 : entry.getValue().entrySet()) { System.out.println("Type : " + entry1.getKey()); } } 
0
source

Source: https://habr.com/ru/post/1447858/


All Articles