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 4274508
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:51:24+00:00 2026-05-21T07:51:24+00:00

Here is my code: // eventList is a LinkedList public void run() { Iterator<Event>

  • 0

Here is my code:

// eventList is a LinkedList

public void run() {

    Iterator<Event> it = eventList.iterator();
    int size = eventList.size();

    while(size > 0) {
        while(it.hasNext()) {
            Event e = it.next(); //flaged line

            if(e.ready()) {
                System.out.println(e);
                e.action();
                eventList.remove(e);
                --size;
            }
        }
    }
}

The error java.util.ConcurrentModificationException is thrown at the flag lined (Event e = it.next();). Do you see a mistake in my code that makes obvious the reason of that exception to be thrown?

  • 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-21T07:51:24+00:00Added an answer on May 21, 2026 at 7:51 am

    Your are modifying eventList while using eventList.remove() while iterating over it. You must not do this, or the Iterator becomes unusable.

    Simply replace eventList.remove(e) with it.remove() and it should be fine.

    Also, you can easily run into an endless loop if one of your events isn’t ready in the first run because it.hasNext() will never return true once it returned false, but size won’t be modified either. One solution would be to move the whole Iterator it = ... line inside the first while loop.

    I’d also modify the outer while loop to use while (!e.isEmpty()) instead of trying to track the size of eventList manually.

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

Sidebar

Related Questions

Here is code example class A{ int i; public: A(int i) : i(i) {}
I have UiTextView where I want change font size (increase), here code -(void)biggerFont:(UIBarButtonItem *)
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
Here's my singleton code (pretty much boilerplate): @interface DataManager : NSObject { NSMutableArray *eventList;
I'm trying to match this block here /code\ int foo(string $bar, int $bleh); Simple
here code delegate void CheckNewsDelegate(); void CheckNews() { frmNews news = new frmNews(); news.Show();
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here my code: $(document).ready(function() { $('#mid_select').live('click', function(e){ $('#middle').load( $(this).attr('href') + ' #middle'); var page
Here is code from a tutorial in A Byte of Python: import sys filename

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.