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 Collections. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Collections." Watch "Collections." New topic
Author

Collections.

Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
Hi all.
Here is the code:

Found this code on this link java.sun. What I would like explaining is the logic in the if statement I have commented. I am not that familier with all the different collection interfaces & classes.
Thanks, Dave.
Mika Leino
Ranch Hand

Joined: Jan 07, 2002
Posts: 56
The TreeSet's add method returns true if the addition was succesful. As the TreeSet, like all Sets, doesn't allow duplicates it will return false when trying to add a String that already exists in the Set.
Don't know if this helps, but another way to present this would be like this:


Mika Leino<br />SCJP, SCWCD
Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
Thanks Mika, I can see the logic clearly now, your'a'good'un!
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
TreeSet implements Set which defines add(), addAll(), remove(), removeAll() and retainAll(), all of which return boolean. Each of these adds or removes objects to/from the set. But adding/removing may turn out to be a no-op (because the specified object is/is-not in the set). So each of these methods returns a boolean which says "I changed the set".


The Inner that is named is not the true Inner.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Collections.
 
Similar Threads
Count duplicates in a TreeSet Collection
Where did I do a mistake ?
Making a binary to decimal converter
K&B - Exercise - try/catch problem
when will == return true for Strings