concurrentmodification

How do you interate over a Collection<T> and modify its items without ConcurrentModificationException?

I need to do something like this... Collection<T> myCollection; ///assume it is initialized and filled for(Iterator<?> index = myCollection.iterator(); index.hasNext();) { Object item = index.next(); myCollection.remove(item); } Obviously this throws ConcurrentModificationException... So I have tried this but doesn't does s...

Exception in thread "AWT-EventQueue-0" java.util.

How do I fix this code? i don't know what this error means... I heard that it comes from having elements of a list removed during a for each loop, but I don't see anything tha I'm removing... public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; for(Layer e : layerList) e.drawLayer(...

Why does one loop throw a ConcurrentModificationException, while the other doesn't?

I've run into this while writing a Traveling Salesman program. For an inner loop, I tried a for(Point x:ArrayList<Point>){ but when adding another point to that list resulted in a ConcurrentModicationException being thrown. However, when I changed the loop to for(int x=0; x<ArrayList<Point>.size(); x++){ the loop ran fine witho...

how to remove ConcurrentModificationException

what is this exception and how to remove this in my problem i am creating an arraylist of objects, and after checking some condition,i want to remove some objects. but the program is giving this exception ConcurrentModificationException. how to remove this thanks in advance ...

synchronized block in JSP tag class

Hi, I am trying to find answer for the following ,for the past couple of days ,but couldnt find comprehensive answer Problem Statement I have a custom JSP tag class which handles a web form submission ,captures data and write it to same file in the filesystem. As all web applications,this can be triggeredsimultaneosly ,and i fear that ...

Performance difference between Iterator Class and foreach construct

I have the following code running, but I sometimes get some sort of concurrency exception when running it. ArrayList<Mob> carriers = new ArrayList<Mob>(); ArrayList<Mob> mobs = new ArrayList<Mob>(); ... for (Mob carrier : carriers){ for (Mob mob : mobs){ checkInfections (carrier, mob); } } I refactored it to solve the...

How can I iterate over an object while modifying it in Java?

Possible Duplicates: Java: Efficient Equivalent to Removing while Iterating a Collection Removing items from a collection in java while iterating over it I'm trying to loop through HashMap: Map<String, Integer> group0 = new HashMap<String, Integer>(); ... and extract every element in group0. This is my approach: // itera...

Cannot append to file when some other process writes to it on *nix systems

I have a very simple piece of code which just writes a small amount of data to a file at some regular interval. Once my program has created the file and appended some data, when I open this file in vim(or any other editor for that matter) and edit it, my process cannot seem to update the file anymore. I do not see any errors being return...