Hello!
I have a question about the lab for Java Collections section of the Java
Programming course. The doc for the lab is 1016-javase-collections.
In exercise 1.3 (finding duplicates using 2 HashSets), the code in
Main.java iterates the input data with a for loop, and puts unique items in
the "uniques" HashSet, and duplicates in the "dups" HashSet.
Following the for loop, removeAll() happens, but I think it might be
redundant?
// Place words that are unique to "uniques" HashSet
// and place that are not to "dups" HashSet.
for (int i=0; i<name.length; i++)
if (!uniques.add(name[i]))
dups.add(name[i]);
// Remove items that duplicates
uniques.removeAll(dups);
This code does nothing, because dups only gets populated after the item is
already checked against uniques. Was this just to show that removeAll
could be used against the HashSet? As the code stands, I don't believe it
does anything.
Please correct me if I'm wrong.
Thanks!
--Ernie
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/groups/opt_out.