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
Why is singleton class used?
How are observer and observable used in java programming?
In a class implementing an interface, can we change the value of any variable defined in the interface?
Why vector class is used?
What is thread pool? How can we create thread pool in java?
What is the difference between serial and throughput garbage collector?
How can I debug the Java security exceptions and AccessControlExceptions?
What is the major difference between linkedlist and arraylist?
what is the volatile modifier for? : Java thread
What is a boolean output?
What is consumer in java?
What is difference overloading and overriding?
What is java command?
Why put method is used?
What is array sorting in java?