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


Please Help Members By Posting Answers For Below Questions

What is map and hashmap in java?

607


What a static class can contains?

682


If you are given the name of the function at run time how will you invoke the function?

669


What are data types in programming?

535


What is singleton math?

563






What is the purpose of a parameter?

512


What’s the difference between constructors and other methods?

518


What is an infinite loop in java? Explain with an example.

570


what are three ways in which a thread can enter the waiting state? : Java thread

561


why are there separate wait and sleep methods? : Java thread

562


What is the indent key?

577


Can anonymous class have constructor?

534


Why is string class considered immutable?

585


Is object a data type in java?

568


What are heterogeneous objects?

556