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 do exponents in java?
What is the purpose of assert keyword used in jdk1.4.x?
What do you understand by the term polymorphism?
Is it possible for a yielded thread to get chance for its execution again?
What is jrmp?
Can we convert integer to string in java?
What is boolean strategy?
Name four container classes.
Why char array is favored over string for the storage of passwords?
How will you load a specific locale?
Can I override protected method in java?
How do you convert boolean to boolean?
Which of the classes will have more memory allocated?
What is an example of a boolean?
Why do we need hashmap in java?