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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:44:51+00:00 2026-05-29T20:44:51+00:00

I use a list of objects, each object contains a number and a string

  • 0

I use a list of objects, each object contains a number and a string name. when a object with the same name is twice in my list i update the number of one of them by 1 and delete the other one, so far so good.

but when i delete a object from this list the iterator still brings back the one i just deleted, it is not in the list anymore, but still has the same location i think.

example:

x 1;
x 1;
y 1;
z 1;

i delete the second x and update the count of the other one:

x 2;
y 1;
z 1;

But now the iterator brings me back the x 1 which was at position two in the beginning, for the iterator it still looks like this:

x 1;
[x1];
y 1;
z 1;

(At least this is what i think what happens, trying it for a few hours now..)

Is there any way to tell the iterator that the list has changed ?
i just read about an remove() method of the iterator, am i right here?

  • 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-29T20:44:52+00:00Added an answer on May 29, 2026 at 8:44 pm

    Yes, you should use the remove method on the iterator to remove the item from the collection, rather than removing the item from the collection directly. In general if you add or remove elements while you are iterating over the collection, then the iterator will no longer work correctly. However calling remove on the iterator will work correctly (if it is implemented).

    Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.

    The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling [remove].


    As a side note, the actual problem you are trying to solve seem to be very similar to the one in this question, so you may also want to look at the answers here for alternative (simpler) approaches:

    • Count occurrences of words in ArrayList
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the .Contains() function on a list of custom objects. This
I've always been one to simply use: List<String> names = new ArrayList<>(); I use
My model contains two objects (Reminders and Users). Each reminder is associated with one
I have these container objects (let's call them Container) in a list. Each of
I have a list of custom objects that I use as the commandName object
I can use ipcs(1) to list out the active shared memory objects on a
I use the following XPATH Query to list the object under a site. ListObject[@Title='SomeValue']
I have an object of type list from which I wish to use to
I made this bash one-liner which I use to list Weblogic instances running along
If you're familiar with ASP.NET's Charting controls, the Chart object contains a number of

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.