File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes annoying problems with sets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "annoying problems with sets" Watch "annoying problems with sets" New topic

annoying problems with sets

Matthew Fyffe

Joined: Jul 11, 2003
Posts: 16
hey, I didn't want to ask here for help but this problem is driving me insane. Here's my code:

The code works perfectly except for one gigantic problem; the time is not removed. The program finds the two lines that are equal to one another and then goes to remove the found line but reports that it was not there, even though it just found that very line. How could that be?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Donno what's happening, but maybe you should look into Iterator.remove instead of Set.remove. Here's a quote from the Iterator.remove doc. The last sentence is a bit scary.

Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Matthew Fyffe

Joined: Jul 11, 2003
Posts: 16
ah yep, seems you were right. Silly me, I thought that only ListIterator had a remove method and thus, went the route I did :-\. Thanks!
I agree. Here's the link:
subject: annoying problems with sets
It's not a secret anymore!