public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
HashMap<String, String> h = new HashMap<String, String>();
h.put("watermelon" , "melon");
h.put("banana" , "fruit");
h.put("cherry" , "fruit");
h.put("pear" , "fruit");
h.put("cantaloupe" , "melon");
h.put("blackberry" , "fruit");
h.put("ginseng" , "root");
h.put("strawberry" , "fruit");
h.put("iris" , "flower");
h.put("potato" , "tuber");
for(HashMap.Entry<String, String> p : map.entrySet())
{
String key = p.getKey(); // Key
String value = p.getValue(); // Value
System.out.println(key + "-" + value);
}
}
identify correction at line 16
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Julián Orellana
27 September 2018, 14:20useful
good morning
in line 16 you writed map.entrySet(), this method get a Set
Set<Map.Entry<K,V>>
you should put the sentence for in this way
for(Map.Entry<String, String> p : map.entrySet())
+1
Ankush Rajput
27 September 2018, 14:26solution
Actually it should be h.entrySet() and not map.entrySet() as the HashMap variable he declared is "h".
+3