title: java: how do I stop people from clearing my arraylist<string> When I use a getter method?
body: <p>I have declared my arraylist in class A:</p>
  
  <pre><code>private ArrayList&lt;String&gt; user = new ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>I have created my getter method in the same class (Class A):</p>
  
  <pre><code>public ArrayList&lt;String&gt; getUser()
  {
  return user;
  }
  </code></pre>
  
  <p>Then in my second class (Class B) I am able to do the following: </p>
  
  <pre><code>A UD = new A();
  UD.getUser().clear();
  UD.getErrmsg().clear();
  </code></pre>
  
  <p>how do I prevent my second class from clearing the arraylist in my first class (class A)?</p>