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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:55:15+00:00 2026-06-09T04:55:15+00:00

Could you please tell is there any way in which concurrent modification exception could

  • 0

Could you please tell is there any way in which concurrent modification exception could occur in a single threaded environment also the below application which I am posting consists of two threads , please tell me can I see the same exception in a single thread also..please advise

package concurrentmodificationError;

import java.util.*;

class ItrDemo
{
    public static void main(String arg[])
    {
       Vector v=new Vector();
       v.addElement("Amit");
       v.add("Rahul");
       v.add(1,"Nitin");
       v.addElement("Ankit");
       System.out.println("There are "+v.size()+"elements in the vector ");

       final Iterator itr=v.iterator();
       Thread th=new Thread()    {
               public void run()
               {
                   System.out.println("New Thread started,traversing     elements of vector...");
                   System.out.println("Contents of vector are...");
                   while(itr.hasNext())
                   {
                     System.out.println(itr.next());
                     try
                      {
                          Thread.sleep(2000);
                       }
                      catch(Exception e1)
                      {
                      }
                   }
              }
         };// end of annomyous class
      System.out.println("Suspending main thread and starting a new thread       for traversing the contents of vector...");
      th.start();
      try
       {
           Thread.sleep(1000);
       }
       catch(Exception e1)
       {
       }
       System.out.println("main thread resumed,modifying vector...");
       v.remove("Ankit");
       v.add("Puneet");
       v.add("Raman");
       System.out.println("Vector Modified , Ankit removed and Puneet &        Raman added.");
  }

}

yeah I got it folks that in the single threaded enviorement this error can comes.. as shown in below piece of code..

System.out.println("Content of list are : ");
          ListIterator itr1=list.listIterator();
          while(itr1.hasNext())
          {
              list.add(new Emp("Anand","Manager",56000)); //
            Emp e=(Emp)itr1.next();  
            e.display();
          }

Please advise what are the ways to overcome it..so that does not get this error..!!Please advise

  • 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-09T04:55:17+00:00Added an answer on June 9, 2026 at 4:55 am

    A ConcurrentModificationException can be thrown in a single thread environment. It is used whenever an object is modified in a context where it shouldn’t, not necessarily in another thread.

    Example:

    public class CME {
        public static void main(String...args) {
            HashSet<Integer> coll = new HashSet<Integer>();
            coll.add(1);
            coll.add(2);
            coll.add(3);
    
            for(Integer i : coll) {
                coll.remove(i); // Throws ConcurrentModificationException
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please tell me if there is a way to capture extra joystick
In Perl, is there any way to tell which .pl script has initialized this
Could someone please tell me why this <%= destroy_password_url @user.password_reset_token %> generates http://localhost:3000/api/destroy_password.4G5EoRVYMUAtiIKqOerKsw routes.rb
Could you please tell me what does @src stands for in action script 3
could someone please tell me what I need to do in order to create
Could someone please tell me what the CodeURI value of a line break is?
Could someone please tell me what I am doing wrong here. I have compiled
Could anyone please tell me why the following line about filter init method invocation
could anyone please tell me, where in Javascript the difference between MyClass.prototype = new
Could you please tell me how can one escape an apostrophe. I need it

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.