-3

I am new to java i got error in HashMap this is what i tried

Hashmap h=new HashMap();
h.put(1,"java");
h.put(2,"c");

but got error

pavan kumar
  • 59
  • 1
  • 2
  • 9
  • it should be `HashMap` not `Hashmap` with upper `M` – YCF_L Jul 07 '17 at 11:40
  • 1. The class HashMap is written wrong 2. You are using a [raw type](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it) which is discouraged. – OH GOD SPIDERS Jul 07 '17 at 11:41

2 Answers2

2

use DataTypes Also Like this is the older procedure to store the values in hashmap

HashMap<Integer,String> h=new HashMap<Integer,String>();
h.put(1,"java");
h.put(2,"c");

It will Work

Pavan Kumar
  • 382
  • 1
  • 6
  • 15
0

For better quality code and low coupling you should use MAP.

Map<Integer,String> h= new HashMap<>();
            h.put(1,"java");
            h.put(2,"c");
Alok Mishra
  • 1,584
  • 1
  • 13
  • 17