title: Protect ArrayList from write access
body: <p>Consider the following class: </p>
  
  <pre><code>public class Cars extends Observable{
  
      private ArrayList&lt;String&gt; carList = new ArrayList&lt;String&gt;();
  
      public void addToCarList(String car){
          // ...
          hasChanged();
          notifyObservers();
      }
  
      public void removeFromCarList(String car){
          // ...
          hasChanged();
          notifyObservers();
      }
  
      public ArrayList&lt;String&gt; getCarList() {
          return carList;
      }    
  }
  </code></pre>
  
  <p>As you can see, every time the carList is changed, I want to notify the <code>Observers</code>. 
  If someone does <code>getCarList().add(...);</code>, this is circumvented. </p>
  
  <p>How can I give read access to the <code>carList</code> (for iterating over it etc.) but prevent write access to it except for the special methods  <code>addToCarList</code> and <code>removeFromCarList</code>? </p>
  
  <p>I thought about this: </p>
  
  <pre><code>public ArrayList&lt;String&gt; getCarList() {
      return (ArrayList&lt;String&gt;)carList.clone();
  }
  </code></pre>
  
  <p>but someone using my class would, when adding something to the clone of <code>carList</code>, not be informed that that's not the way it's meant to be done. </p>