DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2008
    Posts
    3

    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.

  2. #2
    Join Date
    Jul 2008
    Posts
    3

    Smile

    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

  1. a very weird problem (AGAIN!!!)
    By Michael in forum ASP.NET
    Replies: 14
    Last Post: 02-24-2006, 08:54 AM
  2. Josephus Problem, problem.
    By aesoprock00 in forum Java
    Replies: 2
    Last Post: 01-28-2006, 06:18 PM
  3. Replies: 3
    Last Post: 11-16-2005, 06:15 PM
  4. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  5. Replies: 0
    Last Post: 06-23-2000, 02:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links