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 do we need data structure in java?
Can a constructor have different name than a class name in java?
What is polymorphism and what are the types of it?
What is the function of log?
Can we declare the static variables and methods in an abstract class?
What is arraylist class in java?
Print Vertical traversal of a Binary Tree.
Can we have a try block without catch block?
What are the types of java languages?
What is the difference between synchronized and synchronized block?
Explain jvm, jre, and jdk?
How to provide security in java
when to use ArrayList and when to use HashMap in webApplication.
What is boolean flag in java?
How does hashset works in java?