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

Can we have try without catch block?

858


If try block is successfully executed, Then Is Finally block executed?

833


What is time complexity algorithm?

787


What if static is removed from main method?

794


What is array initialization in java?

705


Which variables are stored in stack?

668


Similarity and difference between static block and static method ?

724


Can we create our own daemon thread?

738


Which sorting is used in arrays sort in java?

870


Why put method is used?

770


Explain garbage collection in java?

749


Can variables be used in java without initialization?

798


What are the three types of design patterns?

736


What is the difference between yielding and sleeping in java programming?

807


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

942