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 high level language in computer?
What does sizeof return?
How many bytes is a string in java?
What about static nested classes in java?
What is valid keyword in java?
Is c better than java?
Differences between traditional programming language and object oriented programming language?
What is the difference between a method and a function in alice?
which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?
Which one will take more memory: an int or integer?
What is difference between class and object in java?
Give the difference between the println method and sqrt method?
What are runtime exceptions?
How can an object be unreferenced?
What is the use of arraylist in java?