File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in function remove in Set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in function remove in Set" Watch "Doubt in function remove in Set" New topic
Author

Doubt in function remove in Set

Rikesh Desai
Ranch Hand

Joined: Jun 02, 2010
Posts: 83
Source : Friends notes, not sure of the original source



The questions are in comments. Please help!


OCPJP 95%
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Have a look on the API of remove() method of the HashSet and the equals() method of the Integer class.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Rikesh Desai
Ranch Hand

Joined: Jun 02, 2010
Posts: 83
thanks Abiraman for the pointer!



I added boolean conditions to test whether the elements are actually being removed or not.
And found that i2 here is not being removed!
how come??
then is it that i2 can now never be removed? i added new statements for remove and size and still the size is shown as 1.
Please help! I am getting confused..
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

There is no value 47 in the set so why do you think the method should return true?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rikesh Desai
Ranch Hand

Joined: Jun 02, 2010
Posts: 83
oh! Now i get it!
thanks Wouter!
i was not thinking in the right direction!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in function remove in Set
 
Similar Threads
Adding in a Set
generics question (sample mocks)
HashSet
Confusion on HashSet