Can we place the any object to key attribute of
HashMap<key,value>?
Answer Posted / abhijeet
Hi,
I am giving you a collective answer. Yes you can use any
object as key in hashmap. But if you r sure that u will be
using diferent objects as key then u dont ve to overide
anything. But if you are going to use same object as key
then you need to override hashcode and equals method. Be
sure that your equals method returns false if you need to
use the object as key.
But this is tricky 1 and in live enviroment its not needed :-)
only for interview to impress interviewwer :-)
| Is This Answer Correct ? | 8 Yes | 1 No |
Post New Answer View All Answers
A person says that he compiled a java class successfully without even having a main method in it? Is it possible?
What is java string pool?
What is the difference between assignment and initialization?
Why is whitespace important?
What are the super most classes for all the streams?
Program to Find the second largest element in an array.
What’s a deadlock?
What is java in detail?
What is a null point?
What is string and its types?
What is a constructor, constructor overloading in java?
What is == and === in javascript?
Explain the difference between serializable and externalizable in java?
what is the difference between yielding and sleeping? : Java thread
What is treemap in java?