0

I have a very simple java program that I'm trying to run on VSCode:

import java.util.*;

public class Main {
    public static void main(String[] args){
        Map<Integer, Integer> m = new TreeMap<Integer, Integer>();
        m.put(2, 3);
        m.put(7, 5);
        System.out.println(m.get(7));
    }
}

But for some reason, it always throws this error

[{
    "resource": "/d:/java programming/Main.java",
    "owner": "_generated_diagnostic_collection_name_#2",
    "code": "16777218",
    "severity": 8,
    "message": "TreeMap cannot be resolved to a type",
    "source": "Java",
    "startLineNumber": 5,
    "startColumn": 39,
    "endLineNumber": 5,
    "endColumn": 46
}]

I tried the same thing with other objects like Hashset, Hashmap, map etc. but none of it seems to work

Avyay Nair
  • 23
  • 4
  • In the case of `Hashset` and `Hashmap` you've misspelt the names -- Java is case sensitive. Not sure what the problem with `TreeMap` is. – tgdavies Nov 27 '22 at 09:01

0 Answers0