-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
  • 89
  • 1
  • 2
  • 10

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
  • 412
  • 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,904
  • 1
  • 17
  • 18