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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:00:26+00:00 2026-06-15T08:00:26+00:00

I have a normal Database call that gathers information from my database. i use

  • 0

I have a normal Database call that gathers information from my database. i use these informations to create my objects (CallQueue) these objects are then added to a list and the list is then returned.

Suddenly i discovered that my originally code did not work as intended because i created dublicates and so now i am trying to void that any dublicates are being created! But there is a problem!

I am unable to loop through my list and check wether or not the object is already created!

Here is my code:

while (query.next()) {
    if (!queues.isEmpty()) {
        /*This gives the Execption->*/
        for (CallQueue callQueue : queues) {
            if (callQueue.getType().equals(query.getString("KØ"))) {
                double decimalTime = query.getDouble("TID");
                int hourOfDay = (int)Math.round(24 * decimalTime);
                int callAmount = query.getInteger("ANTAL_KALD");
                if (hourOfDay > 19) {
                    hourOfDay = 19;
                }
                callQueue.addCallsByTime(hourOfDay, callAmount);
            } else {
                String queueName = query.getString("Kø");
                if (!queueName.equalsIgnoreCase("PrivatOverflow")) {
                    CallQueue cq = new CallQueue(query.getString("KØ"));
                    double decimalTime = query.getDouble("TID");
                    int hourOfDay = (int)Math.round(24 * decimalTime); 
                    int callAmount = query.getInteger("ANTAL_KALD");
                    if (hourOfDay > 19) {
                        hourOfDay = 19;
                    }
                    cq.addCallsByTime(hourOfDay, callAmount);
                    queues.add(cq);
                }
            }
        }
    } else {
        String queueName = query.getString("Kø");
        if (!queueName.equalsIgnoreCase("PrivatOverflow")) {
            CallQueue cq = new CallQueue(query.getString("KØ"));
            double decimalTime = query.getDouble("TID");
            int hourOfDay = (int)Math.round(24 * decimalTime); 
            int callAmount = query.getInteger("ANTAL_KALD");
            if (hourOfDay > 19) {
                hourOfDay = 19;
            }
            cq.addCallsByTime(hourOfDay, callAmount);
            queues.add(cq);
        }
    }
}

for (CallQueue callQueue : queues) {
    System.out.println(callQueue.getType());
}
query.Close();
return queues;

The execption i get from this is:

Caused by: java.util.ConcurrentModificationException

ive tried to look up the execption at ConcurrentModificationException

Can anyone help me fix this problem?

  • 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-15T08:00:28+00:00Added an answer on June 15, 2026 at 8:00 am

    You’re doing an add inside of your iteration. As per the spec, you’re not allowed to modify the collection you’re iterating over.

    The classic solution is to make a copy of the collection first and iterate over that instead. Another solution is to not use the iterator (the short foreach notation is using it implicitly) but to manually iterate using an index.

    for (int i=0; i<queues.size(); i++) {
        CallQueue callQueue = queues.get(i);
    
        ... code goes here
    
    }
    

    A better solution would be to use a Set instead of a list (unless the order is important for you). That does mean you would have to implement equals and hashcode properly.

    Btw: I believe your code is flawed. You’re iterating over your list, and if the item you encounter does not match, you add one at the end. Meaning that, if the item you’re looking for is the xth one in the list, you will have added a new item x times. I seriously doubt that is what you need. If you do some refactoring, this will become immediately clear.

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

Sidebar

Related Questions

I have normal sqlite database and want to use fts3. As mentioned in http://www.sqlite.org/fts3.html
I have a database stored procedure call that, among other columns, returns a column
I have a normal asp.net page containing some code that I want to measure
I have read that 'Normal' ARM instructions are fixed length - 32 bits. And
Is it normal to have tests that are way bigger than the actual code
I have turned a normal PHP class into a library so I can use
I have an application in mind which dicates database tables be append-only; that is,
I have a database manager which successfully loads a string from my sqlite database,
i have a model class that represents a table in a database. The table
I have a page that is dynamically built by the database. For each thing

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.