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...

If set accepts only one argument then how can it compare
two objects to avoid duplicates

Answer Posted / suresh

if the adding element is the first element, then the
element will be added directly to set stream. If there are
elements is Set the first.
1. while adding the new element to set hashcode will be
generated to element by using hashCode() method.
2.Then generated hash code will be compare with each and
every element of the Set by using equels() method. if
equels method retunrs false then the element will be added
to Set else the element will be discarded.

So, in order to avoid the duplicats we have to override
both equels and hash code methods.

If above given info is wrong, plse let me know at
sureshamca47@gmail.com

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are void pointers?

1219


What are the access modifiers in java?

982


What is jagged array in java?

1007


Explain throw keyword in java?

992


What are mutable classes?

969


Why we used break and continue statement in java?

1061


what do you mean by classloader in java?

974


Can we use a switch statement with strings?

974


What are the 7 types of characters?

1019


Why is multithreading important?

889


Name component subclasses that support painting in java programming?

1012


When do I need to use reflection feature in java?

1008


What is a local, member and a class variable?

972


What is Garbage Collection in Java

1027


Why we go for collections in java?

919