Click here to Skip to main content
15,881,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to pass two Objects as parameters while creating Hash Map.One Object as Key and Other as Value.Is it possible using Hash Map?

What I have tried:

Java
Map m=new HashMap();
Employee e=new Employee(1,"Rajesh");
Department d=new Department(10,1);//1 is employee id here 

m.put(e,d);

What is the wrong Iam doing
Posted
Updated 19-Mar-16 3:10am
v2
Comments
Richard MacCutchan 19-Mar-16 9:14am    
I think you need to declare the types used in the map. something like:
Map m = new HashMap<Employee, Department>();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900