title: Multiple threads editing an ArrayList and its objects
body: <p>I am trying to run 2 concurrent threads, where one keeps adding objects to a list and the other updates these objects and may remove some of these objects from the list as well.
  I have a whole project where I've used <code>ArrayList</code> for my methods and classes so it's difficult to change it now.</p>
  
  <p>I've looked around and I found a few ways of doing this, but as I said it is difficult to change from <code>ArrayList</code>. I tried using <code>synchronized</code> and <code>notify()</code> for the method adding the objects to the list and <code>wait()</code> for the method changing these objects and potentially removing them if they meet certain criteria.</p>
  
  <p>Now, I've figured out how to do this using a <code>CopyOnWriteArrayList</code>, but I would like to know if there's a possibility of using <code>ArrayList</code> itself to simulate this. so that I don't have to edit my entire code.</p>
  
  <p>So, basically, I would like to do something like this, but with <code>ArrayList</code>:</p>
  
  <pre><code>import java.util.Iterator;
  import java.util.concurrent.CopyOnWriteArrayList;
  
  public class ListExample{
      CopyOnWriteArrayList&lt;MyObject&gt; syncList;
  
      public ListExample(){
          syncList = new CopyOnWriteArrayList&lt;MyObject&gt;();
  
          Thread thread1 = new Thread(){
              public void run(){
                  synchronized (syncList){
                      for(int i = 0; i &lt; 10; i++){
                          syncList.add(new MyObject(i));
                      }
                  }
              }
          };
  
          Thread thread2 = new Thread(){
              public void run(){
                  synchronized (syncList){
                      Iterator&lt;MyObject&gt; iterator = syncList.iterator();
                      while(iterator.hasNext()){
                          MyObject temp = iterator.next();
  
                          //this is just a sample list manipulation
                          if (temp.getID() &gt; 3)
                              syncList.remove(temp);
  
                          System.out.println("Object ID: " + temp.getID() + " AND list size: " + syncList.size());
                      }
                  }
              }
          };
  
          thread1.start();
          thread2.start();
      }
  
      public static void main(String[] args){
          new ListExample();
      }
  }
  
  class MyObject{
      private int ID;
  
      public MyObject(int ID){
          this.ID = ID;
      }
  
      public int getID(){
          return ID;
      }
  
      public void setID(int ID){
          this.ID = ID;
      }
  }
  </code></pre>
  
  <p>I've also read about <code>Collections.synchronizedList(new ArrayList())</code> but again, I believe this would require me to change my code as I have a substantial number of methods that take <code>ArrayList</code> as a parameter.</p>
  
  <p>Any guidance would be appreciated, because I am out of ideas. Thank you.</p>