The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Not Sorted Properly

Posted by Fisher on June 28, 2001 at 4:12 AM

> I use TreeSet to contain objects.

>
> PseudoCode:
>
>
> Object o = m_TreeSet.first();
> boolean b = m_TreeSet.remove (o);
> Object o1 = m_TreeSet.first();

> After program runs some time, this piece of code does not do
> what it should do, i.e. remove() return a false.
> o (Object), which is not null, is not be removed from the container.
> That is that o1 is the same as o.

> Please help me to avoid this isue.

> Thanks a lot.
>

>
>
>

I worked on this problem for two days. Finally, I found the reason,
which is because I changed the member variables in the objects of
TreeSet container, thus TreeSet Object is not sorted properly anymore.

In summary, some functions in TreeSet will fail when it is not sorted properly.

Fisher






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us