Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Why do we need data structure in java?

1016


Can a constructor have different name than a class name in java?

1082


What is polymorphism and what are the types of it?

938


What is the function of log?

944


Can we declare the static variables and methods in an abstract class?

934


What is arraylist class in java?

989


Print Vertical traversal of a Binary Tree.

978


Can we have a try block without catch block?

939


What are the types of java languages?

928


What is the difference between synchronized and synchronized block?

1002


Explain jvm, jre, and jdk?

953


How to provide security in java

2194


when to use ArrayList and when to use HashMap in webApplication.

4585


What is boolean flag in java?

1033


How does hashset works in java?

999