7) Suppose there is Student class like
class student {
int age;
string name;
}
We want to store these objects in a HashMap. Do we need to
override any methods in Student class? If any which ones
and why? what if i just override equals or just hashcode?
what will be the results in both the cases?
Answer Posted / lucky singh
It is a good practice to override equals() and hashcode()
methods if you are dealing with collections. Both of the
functions are used while searching for a particular object
in a hashmap. In general, equals() method is used to
determine if two objects are meaningfully equal or not. And
hashcode() method is used to determine if two objects are
meaningfully unequal or not.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is the difference between delete and delete[]
Is ++ operator thread-safe in java?
What type of value does sizeof return?
What is boolean in java?
what is the difference between Object Based Language and Object Oriented Language?
Is void a keyword in java?
What is purpose of keyword void?
When do we use synchronized blocks and advantages of using synchronized blocks?
What is length in java?
How many types of memory areas are allocated by jvm?
Write a program to check string is palindrome without using loop?
Is java call by reference?
What is finally block?
Can we override constructor?
What are the disadvantages of object oriented programming?