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


Please Help Members By Posting Answers For Below Questions

What is slash r?

532


What is quick sort in java?

547


Can the interface be final?

570


What does opcode mean?

524


What is a parameter example?

518






What are "class access modifiers" in Java?

602


Define inheritance?

542


what is the final keyword denotes in java?

575


Why java is used everywhere?

584


How to sort double array in java?

583


What's the difference between comparison done by equals method and == operator?

534


Why can't you declare a class as protected?

589


Why set do not allow duplicates in java?

571


What is empty list in java?

613


What is the symbol for space?

558