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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:37:59+00:00 2026-06-13T12:37:59+00:00

I have an arraylist with names, phone numbers and locations. I would like to

  • 0

I have an arraylist with names, phone numbers and locations.

I would like to remove certain items from that array if possible

Is there anyway to remove the item once I have found it like I have tried below?

public void delete(String nameToDelete) 
{    
    for (Entry entry : Directory.entries) { 
        if (entry.name.equalsIgnoreCase(nameToDelete))
        {
            //remove(entry);
        }
    }
}

Thanks

  • 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-13T12:38:00+00:00Added an answer on June 13, 2026 at 12:38 pm

    Reason?

    Iterators returned by ArrayList is fail-fast in nature.

    The iterators returned by this class’s iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator’s own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

    Where does this iterator Come from while I am not using it?

    For enhanced for loop for collections Iterator gets used so you can not call remove method while you are iterating.

    So your loop is same as below

    for (Iterator<Entry> i = c.iterator(); i.hasNext(); ){   
    

    What is the Solution Then ?

    You can call iterator.remove(); and change loop based on iterator explicitly rather than implicitly.

        String inputWord = "john";
        ArrayList<String> wordlist = new ArrayList<String>();
        wordlist.add("rambo");
        wordlist.add("john");
        for (ListIterator<String> iterator = wordlist.listIterator(); iterator
                .hasNext();) {
            String z = iterator.next();
            if (z.equals(inputWord)) {
                iterator.remove();
            }
        }
        System.out.println(wordlist.size());
    

    Now Where Can I Read more?

    1. The For-Each Loop
    2. ArrayList Java docs
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an arraylist that holds a subset of names found in my database.
I would like to put the phone contacts on my phone to an Array.
I have an ArrayList containing Car objects and I want to get from that
I have an arraylist with multiple hashmaps that contains information that comes from a
I have an arraylist called fetchContactName() which returns all names (31) in my contact
I have wriiten a method like this public ArrayList<T> GetDoctorDetail(String name) { if (name!=null
I have an ArrayList of HashMap like this: ArrayList<HashMap<String, String>> playListSongs = new ArrayList<HashMap<String,
I have a question, that i am getting a JSON response from a by
I have a phone object and a phone history object. I'd like to be
I have an Android application that displays a list of names using checkboxes. I

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.