While using integer in the place of int it's working. Why not with int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

While using integer in the place of int it's working. Why not with int

import java.util.HashMap ; class MyClass { public static void main(String[]args){ //in the below object if I change Integer with int it's working. explain me why it's not working with int HashMap<String,int> f = new HashMap<String,int>(); f.put("senthil",200); f.put("santy",100); System.out.println(f.get("santy")); } }

16th Mar 2018, 7:32 AM
Marana Coder
Marana Coder - avatar
2 Answers
+ 6
int will not work because you have to specific an object type not a primitive type. Integer is an wrapper class for int https://www.sololearn.com/learn/432/?ref=app
16th Mar 2018, 7:35 AM
David Akhihiero
David Akhihiero - avatar
0
Because you have specific it an objective type not a primitive type
4th Jun 2020, 6:52 AM
Sri Pujitha
Sri Pujitha - avatar