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 / krishna
There is no need to override equals() and hashCode() methods. But if we want to eliminate duplicate objects in the HashMap, you should override both the methods. Either one is not enough.
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is map and hashmap in java?
What a static class can contains?
If you are given the name of the function at run time how will you invoke the function?
What are data types in programming?
What is singleton math?
What is the purpose of a parameter?
What’s the difference between constructors and other methods?
What is an infinite loop in java? Explain with an example.
what are three ways in which a thread can enter the waiting state? : Java thread
why are there separate wait and sleep methods? : Java thread
What is the indent key?
Can anonymous class have constructor?
Why is string class considered immutable?
Is object a data type in java?
What are heterogeneous objects?