Create a collection HashMap<string, string="">, place 10 pairs of strings into the collection: watermelon - berry, banana - grass, cherry - berry, pear - fruit, melon - vegetable, blackberry - berry, ginseng - root, strawberry - berry, iris - flower, potato - tuber. Display to the screen the contents of the collection. Each entry should be on a new line.

Output example (only one string is shown): potato - tuber Works fine, but didn't passed. Any idea?

public class Solution


public static void main(String[] args) throws Exception
    Map<String, String> map = new HashMap<String, String>();
    map.put("watermelon", "berry");
    map.put("cherry", "berry");
    map.put("pear", "fruit");
    map.put("melon", "vegetable");
    map.put("blackberry", "berry");
    map.put("ginseng", "root");
    map.put("strawberry", "berry");
    map.put("iris", "flower");
    map.put("potato", "tuber");

    for (Map.Entry<String, String> pair : map.entrySet())
        String key = pair.getKey();
        String value = pair.getValue();
        System.out.println(key + " - " + value);


asked 02 Sep, 09:01

Demotivator's gravatar image

accept rate: 0%

edited 02 Sep, 09:02

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 02 Sep, 09:01

Seen: 54 times

Last updated: 02 Sep, 09:02