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
How do you check if two given string are anagrams?
How do I print a “?
What is the purpose of finalization in java programming?
How do you declare a variable?
What is a newline character in java?
What are the super most classes for all the streams?
What is meant by inheritance and what are its advantages?
does java support pointers?
What are the different types of methodologies?
Why java is object oriented?
What is the use of hashmap in java?
What is string literal in java?
What is a parameter in a function?
What is string pool?
Is space a character in java?