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
Can a class have multiple constructors?
What is a subsequence of a string?
How many java versions are there?
Are strings immutable in java?
What causes memory leaks in java?
How do you invoke a method?
Can an unreferenced object be referenced again?
Can a class extend more than one class?
What does escaping a character mean?
What is an object's lock and which object's have locks in java programming?
Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.
How an object is serialized in java?
Define inheritance with reference to java.
What is the significance of continue jump statement? Explain with an example.
What do you mean by object?