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 is singleton class used?

1088


How are observer and observable used in java programming?

1080


In a class implementing an interface, can we change the value of any variable defined in the interface?

1145


Why vector class is used?

1037


What is thread pool? How can we create thread pool in java?

1140


What is the difference between serial and throughput garbage collector?

1160


How can I debug the Java security exceptions and AccessControlExceptions?

1202


What is the major difference between linkedlist and arraylist?

1122


what is the volatile modifier for? : Java thread

1063


What is a boolean output?

1026


What is consumer in java?

1015


What is difference overloading and overriding?

1250


What is java command?

1130


Why put method is used?

1058


What is array sorting in java?

1112