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

explain autoboxing in java?

942


how to run ecllipse with jettyserver for windows environment using batch file

2018


What are the wrapped, classes?

1015


Why is method overloading not possible by changing the return type in java?

957


What is bufferedwriter?

924


What are the main concepts of oops in java?

1636


Explain the different forms of polymorphism?

958


Can we catch more than one exception in single catch block?

1002


Variables used in a switch statement can be used with which datatypes?

943


What is java instanceof operator?

993


Why are functions called methods in java?

953


What are the differences between string and stringbuffer?

1072


How many threads can I run java?

1056


Explain when we should make an instance variable private.

1054


Tell me how many ways are there to initialise an integer with a constant.

1067