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

What is arraylist e in java?

500


What does it mean to flush a file?

557


How to implement a multithreaded applet?

2195


How we can run a jar file through command prompt in java?

508


Can we define private and protected modifiers for the members in interfaces?

525






What is a nullable field?

565


What is static in java?

548


How to sort array of 0 and 1 in java?

536


What are the escape sequences in java?

556


Can you override a final method?

569


give an example for encapsulation?

569


Is c better than java?

533


What is the simpletimezone class in java programming?

527


What is primitive array?

511


What is the maximum size of a string in java?

539