title: Does modifying the result of a getter affect the object itself?
body: <p>I have a question about using getter methods in java.
  Suppose I had this class:</p>
  
  <pre><code>class Test {
      private ArrayList&lt;String&gt; array = new ArrayList&lt;String&gt;();
  
      public ArrayList getArray() {
          return this.array;
      }
  
      public void initArray() {
          array.add("Test 1");
          array.add("Test 2");
      }
  }
  
  class Start {
      public static void main(String args[]) {
          initArray();
          getArray().remove(0);
      }
  } 
  </code></pre>
  
  <p>My question is:</p>
  
  <p>Would the actual arraylist object be modified ("Test 1" removed from it)? I think I have seen this in places, but I thought that getters were simply providing a copy of that object. Not a reference to it. If it did work that way (as a reference), then would this work as well (Would the arraylist object of the class Test be altered by this as well)?:</p>
  
  <pre><code>class Start {
      public static void main(String args[]) {
          initArray();
          ArrayList aVar = getArray();
          aVar.remove(0);
      }
  } 
  </code></pre>