LearnFrenzy
Sign in Take a free test

HashMap and TreeMap · Find the Error · Question 1

Error: Map with one type argument Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Map<String> phone = new HashMap<>();
        System.out.println(phone);
    }
}
  • A HashMap needs a capacity
  • B Map takes two type arguments – the key type and the value type, e.g. Map<String, String> Correct
  • C Map must be imported from java.lang
  • D println cannot print maps
Correct Answer: Option B

javac: "wrong number of type arguments; required 2".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links