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

What is high level language in computer?

1023


What does sizeof return?

994


How many bytes is a string in java?

1002


What about static nested classes in java?

1151


What is valid keyword in java?

1002


Is c better than java?

964


Differences between traditional programming language and object oriented programming language?

1130


What is the difference between a method and a function in alice?

1202


which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?

11214


Which one will take more memory: an int or integer?

1237


What is difference between class and object in java?

1079


Give the difference between the println method and sqrt method?

1086


What are runtime exceptions?

1163


How can an object be unreferenced?

1025


What is the use of arraylist in java?

1096