Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 809237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:41:43+00:00 2026-05-15T00:41:43+00:00

I have a SortedSet holding my ordered data. I use the .first() method to

  • 0

I have a SortedSet holding my ordered data.

I use the .first() method to return the first record, and pass it to another window.
When the other window finishes I get an event called, and I want to pass the next from the SortedSet to the window, so how to move to the next element?

launchWindow(this.set.first());

Then I have this:

onActivityResult(...) {
 if (this.set.hasNext()) launchWindow(this.set.next());//hasNext/next doesn't exists in the current context for SortedSet
}

What options I have?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:41:44+00:00Added an answer on May 15, 2026 at 12:41 am

    The iterator solution:

    You should probably have something like this:

    class WindowLauncherClass {
    
       SortedSet set = null;
       Iterator setIterator = null;
    
       public WindowLauncherClass(SortedSet set) {
          this.set = set; // or you can copy it if that's what you need.
       }
    
       protected void launchWindow(Object item) {
         // impl 
       }
    
       public void onActivityResult() {
          if ( setIterator != null && setIterator.hasNext() ) 
          {   
             launchWindow(setIterator.next());
          }
       }
    
       public void start() {
           setIterator = set.iterator();
           onActivityResult();
       }
    }
    

    In the comments appeared the question about updates to the set. Will the iterator see it ?.
    The normal answer is depends on the application requirements. In this case i don’t have all the information and i’ll try to guess.

    1. until jdk 1.5 there was only one SortedSet implementstion ( TreeSet ). this had a fail fast iterator.

    2. in jdk 6 appeared a new implementation: ConcurrentSkipListSet. The iterator for this sorted set is not a fail fast one.

    If you are adding an element into the set that is “smaller” than the currently displayed element then you will not be able to see it anyway by a “good” (not fail fast) iterator. If you are adding an element “bigger” that the currently displayed element you will see it by a proper iterator.

    The final solution is to actually reset the set and the iterator when a proper change is created. By using a ConcurrentSkipListSet initially you will see only the “bigger” changes and by using a TreeSet you will fail at every update.

    If you afford to miss updates “smaller” than the current one then go for the jdk 6.0 and ConcurrentSkipListSet. If not than you’ll have to keep track of what you displayed and rebuild a proper set with new items and undisplayed items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a method that is to return a TreeSet of integers how
I'm trying to use .NET 4's SortedSet<T> collection. It seems to have everything I
I have these two data structures: public TreeMap<String, Integer> tableFrequency; public SortedSet<Map.Entry<String, Integer>> sortedTable;
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a SortedSet defined this way: SortedSet<RatedMessage> messageCollection = new TreeSet<RatedMessage>(new Comp()); and
I have a class : class Category { String name SortedSet items static hasMany
I have a service that produces as result a SortedSet object. I need to
I have this before the process: protected void onPostExecute(SortedSet<RatedMessage> result) { List<Object> list=Arrays.asList(result.toArray()); lancon.putExtra(results,
As far as I know, things such as SortedMap or SortedSet , use compareTo
I have a big number of SortedSet<Long> structures: 1, 2, 5, 8, 10, 35,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.