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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:21:34+00:00 2026-06-11T14:21:34+00:00

I have LinkedList of objects and an iterator. I know that this ConcurrentModificationException is

  • 0

I have LinkedList of objects and an iterator. I know that this ConcurrentModificationException is thrown when you try to modify the list while running the iterator. But in my case, I don’t understand where this modification is being done.

The iterator looks like this :

private static void insertTasks(Task t) {
    if(eventQueue.size() == 0) {
        eventQueue.addFirst(tsk);
        return;
    }

    int pos = 0;
    while (itr.hasNext()){
   //The line below throws the exception

        if (t.getArrivalTime() <= itr.next().getArrivalTime() ) 
        {           
            break;
        }
        pos++;
    }
}

I am calling this insertTasks method from another method as shown below :

tsk = null;
tsk = new Task(1,"P1",1,4.0f,1.5f,0.0f,8.0f);
insertTasks(tsk);

tsk = null;
tsk = new Task(0,"P0",2,5.0f,2.5f,1.0f,10.0f);
insertTasks(tsk);

The getArrivalTime in the Task objects looks like :

public float getArrivalTime() { return arrivalTime; }

My question is, where am I doing this modification ? The while loop where I run this iterator is not doing any modification. Does it ?

Am I missing something ?

  • 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-11T14:21:35+00:00Added an answer on June 11, 2026 at 2:21 pm

    I reckon the problem is that itr is a static field in your class and that’s creating the issue, as you’re adding an element to eventQueue in your second call to insertTasks().

    Avoid static fields… program yourself to fear them and avoid them as much as you can :). They evil, and OO unfriendly.

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

Sidebar

Related Questions

I have two LinkedList objects that are always of the same size. I want
I have a LinkedList that contains many objects. How can I find the number
I have a class that looks like this: typedef std::list<char*> PtrList; class Foo {
I guess this question that would have already been asked here. I searched but
I have a set of objects (stored in a linkedlist) that need to be
I have one thread that add() s objects into a LinkedList queue, and another
If I have an LinkedList of Employee objects... Each employee has a Name, and
If I have a collection of objects: public class Party { LinkedList<Guy> partyList =
I have to implement a one linked list but it should put object in
I have a LinkedList as /** * The list of data to display. */

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.