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
Define array. Tell me about 2-D array.
What modifiers may be used with an inner class that is a member of an outer class in java programming?
How to use Media tracker Class.
Is a boolean variable?
What are different types of control structures?
Does a function need a return?
what is method reference in java 8?
Difference between error and exception
What is the escape character in java?
How is java created?
Justify your answer that you can't define a method inside another method in java, if you can then how?
In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?
What mechanism does java use for memory management?
Can we catch more than one exception in single catch block?
Difference between static binding and dynamic binding?