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 ternary operator in java?

831


Why does java doesnt suuport unsigned values?

2002


what is synchronization and why is it important? : Java thread

866


How to sort an array from smallest to largest java?

804


How to perform bubble sort in java?

803


Is namespace same as package in java?

761


Can we create a constructor in abstract class?

779


Which eclipse is best for java?

764


Why is it important to initialize a variable?

755


Can we sort set in java?

757


What is the difference between static (class) method and instance method?

817


What is collection sort in java?

775


What is the difference between quicksort & mergesort? When should they be used? What is their running time?

859


How do you escape a string?

741


What happens if we override private method?

766