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

  • SEARCH
  • Home
  • 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 8139041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:41:49+00:00 2026-06-06T11:41:49+00:00

I am interested if there is any framework that implements a collection that would

  • 0

I am interested if there is any framework that implements a collection that would have the following behavior.


Suppose it initially contains: [1, 2, 3]

  • I iterate it (using an iterator) and reach element 2, now I add 4 to the end (the collection will now be [1, 2, 3, 4]).
  • now I create a new iterator and iterate the collection, resulting in [1, 2, 3, 4]
  • I continue iterating with the first iterator and it will give me just 3 and return
  • now resetting the first iterator will give me [1, 2, 3, 4] (similar to creating a new one).

Same should apply for removal of elements. If I remove 3 instead of adding, the second iterator should give me [1, 2] while the first one will still give me 3 and the end.


So when I get and iterator I want it to give me the collection I had when I created the iterator (even if I iterate it later, on I iterate a bit and continue later), when I reset the iterator, it gets garbage collected it will update to the latest versions and I should be able to have multiple iterator instances created at different times that will give different versions depending on the contents of the array when the iterator was created.

I would need it to work well with multiple threads and preferable have an efficient implementation.

Does anyone know of any implementation of such a collection, or do I have to implement it myself?

  • 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-06-06T11:41:50+00:00Added an answer on June 6, 2026 at 11:41 am

    What you describe looks very similar to how CopyOnWriteArrayList works:

    • once you start iterating, you can change the collection (including from another thread) without affecting the iteration
    • if you create a new iterator it will be based on the collection at the creation time
    • it is thread safe

    Simple example below with the following output:

    Iterator 1 – 1
    4 has been added
    Iterator 2 – 1
    Iterator 2 – 2
    Iterator 2 – 3
    Iterator 2 – 4
    Iterator 1 – 2
    Iterator 1 – 3

    public static void main(String[] args) throws InterruptedException {
        final List<Integer> list = new CopyOnWriteArrayList<Integer>();
        list.addAll(Arrays.asList(1, 2, 3));
        new Thread(new Runnable() {
    
            @Override
            public void run() {
                for (Integer i : list) {
                    System.out.println("Iterator 1 - " + i);
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {}
                }
            }
        }).start();
        Thread.sleep(10);
        list.add(4);
        System.out.println("4 has been added");
        for (Integer i : list) {
            System.out.println("Iterator 2 - " + i);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any products out there that convert Flash SWFs to XAML (I'm interested
If there's any open source code that does this already I'm interested in hearing
Are there any open-source examples of ASP.NET MVC applications that use the Entity Framework?
Is there any freely available library (other than java media framework) that I can
I'm interested if there is any function like array_map or array_walk from php. Don't
There are many things that all programmers should know, but I am particularly interested
I know that the Collection framework allows for the creation of views, that is
I am interested in writing a method that would accept another method as a
We have a data model that has some requirements. I would like to find
We have a .NET project that uses WMI and are interested in porting it

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.