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
What is the original name of java?
What is the importance of hashcode() and equals() methods?
What is wrapper class html?
Explain about automatic type conversion in java?
What is a databasemetadata?
Is java ee a framework?
What do you mean by pointer value and address?
How can I debug the Java security exceptions and AccessControlExceptions?
What is this keyword in java?
Can we pass null as argument in java?
what are three ways in which a thread can enter the waiting state? Or what are different ways in which a thread can enter the waiting state? : Java thread
Explain about anonymous inner classes in java?
What are recursive functions?
Can we override private method?
Difference between final and effectively final ?