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 arraylist e in java?
What does it mean to flush a file?
How to implement a multithreaded applet?
How we can run a jar file through command prompt in java?
Can we define private and protected modifiers for the members in interfaces?
What is a nullable field?
What is static in java?
How to sort array of 0 and 1 in java?
What are the escape sequences in java?
Can you override a final method?
give an example for encapsulation?
Is c better than java?
What is the simpletimezone class in java programming?
What is primitive array?
What is the maximum size of a string in java?