-
TreeSet problem: last() returns with NoSuchElementException
Hi all!
I have a small problem using TreeSet.
Given:
I am using a TreeSet with a comparator. While I have debugged my application I found that I have some elements in this set but I got a NoSuchElementException when I try to get the last element.
SortedSet<TimeBarSection> elementsBefore = sections.headSet(section);
return elementsBefore.isEmpty() ? null : elementsBefore.last();
where sections is the TreeSet I mnetioned above.
Thank you for your comments.
-
Hi again!
I found a solution (workaround?!):
TreeSet<TimeBarSection> elementsBefore = new TreeSet<TimeBarSection>(TimeBarSection.BY_START_COMPARATOR);
elementsBefore.addAll(sections.headSet(section));
In this case I could see the whole structutre of the tree (root, left, right,...).
Does anyone have any idea why it works in this way?
Thx
Similar Threads
-
By Michael in forum ASP.NET
Replies: 14
Last Post: 02-24-2006, 08:54 AM
-
By aesoprock00 in forum Java
Replies: 2
Last Post: 01-28-2006, 06:18 PM
-
By JohnsonGPS in forum C++
Replies: 3
Last Post: 11-16-2005, 06:15 PM
-
Replies: 0
Last Post: 12-13-2001, 12:06 PM
-
By Wade Balzer in forum VB Classic
Replies: 0
Last Post: 06-23-2000, 02:17 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks