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

Why 1 is not a prime number?

563


Write a program to check string is palindrome without using loop?

570


What is sorting algorithm in java?

527


What’s the difference between applets and standalone program?

534


What is a functional interface?

549






When should you make a function static?

547


What is JDBC Driver interface?How can you retrieve data from the ResultSet

1515


What is a hashmap used for?

652


Explain constructors and types of constructors in java.

646


What is the function of java?

517


What is the difference between a break statement and a continue statement?

603


Explain how to convert any java object into byte array.

558


Why does java not support pointers?

556


What does pointer mean?

546


What is immutable in java?

550