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


Please Help Members By Posting Answers For Below Questions

Define array. Tell me about 2-D array.

589


What modifiers may be used with an inner class that is a member of an outer class in java programming?

535


How to use Media tracker Class.

648


Is a boolean variable?

523


What are different types of control structures?

495






Does a function need a return?

533


what is method reference in java 8?

558


Difference between error and exception

5023


What is the escape character in java?

515


How is java created?

536


Justify your answer that you can't define a method inside another method in java, if you can then how?

606


In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?

841


What mechanism does java use for memory management?

494


Can we catch more than one exception in single catch block?

603


Difference between static binding and dynamic binding?

568