[Solved] Can HashMap contain custom class for key/value?


In hashmap, yes you can include custom types as Key/Value pair.

but that should not be object , it must of clearly a type .

means a class you can mention which becomes type for custom types.

example ,

you can define String type variable as String s = "abc";

now
if we try to write like below

HashMap<String, s> a= new HashMap<String, s>();

it wont compile as 's' is not the type rather than its an object of type String,

hence it should become like below

HashMap<String, String> a= new HashMap<String, String>();

so your code like below

Test test=new Test();       
        HashMap<String, test> a= new HashMap<String, test>();

should become

Test test=new Test();       
        HashMap<String, Test> a= new HashMap<String, Test>();

0

solved Can HashMap contain custom class for key/value?