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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:57:25+00:00 2026-05-14T22:57:25+00:00

Take this Java code: for (ContactsReduced curContact : allcontacts) { ………. allcontacts.remove(curContact); } I

  • 0

Take this Java code:

for (ContactsReduced curContact : allcontacts) {
 ..........
 allcontacts.remove(curContact);
}

I do based on a condition a remove, will the foreach miss the next item in order, and do we need to step back(somehow)?

  • 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-14T22:57:26+00:00Added an answer on May 14, 2026 at 10:57 pm

    That code will break with most collections – other than a few collections such as those in java.util.concurrent, modifying a collection while iterating over it isn’t supported.

    A few options:

    • Obtain and use an iterator explicitly (call iterator() on the collection) instead of an enhanced for loop, and call iterator.remove() to remove an item
    • Use a plain for loop, either moving forwards and stepping back after the removal or moving backwards from the end
    • Maintain a separate list of items to remove, and then remove them after iterating
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are $@ and $* which contain a list of… May 16, 2026 at 12:23 pm
  • Editorial Team
    Editorial Team added an answer Just a warning before we get started that the solution… May 16, 2026 at 12:23 pm
  • Editorial Team
    Editorial Team added an answer You can use VTE, a terminal emulator widget. I'm not… May 16, 2026 at 12:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have this java code: if(isNull(office) || isNull(pricelist)) { log.warn(The document {0}-{1} is not
I am writing a piece of code in Java that needs to take a
Say I want to create a sort of Pre-processor for existing java code, so
I'm using TPTP to profile some slow running Java code an I came across
In the Java code for our application I'm pretty sure there are lots of
Take this for example: http://en.wikipedia.org/wiki/United_States_Bill_of_Rights Under the Amendments section, I want to get what
When I compile something like this: public class MyClass { void myMethod(String name, String
I'm wondering if there is a tool for documenting the java application. I mean
I have an application in java swing which runs in the system tray most
This is for the swing experts out there. I have spent considerable time on

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.