title: ArrayLists not working as expected
body: <pre><code>import java.util.ArrayList;
  
  public class bugs 
  {
      public ArrayList&lt;Integer&gt; elements1;
      public ArrayList&lt;Integer&gt; elements2;
  
      public bugs(ArrayList&lt;Integer&gt; args)
      {
          elements1 = args;
          elements2 = args;
      }
  
      public void change(int index, int value)
      {
          elements1.set(index, value);
      }
  
      public void reset()
      {
          elements1 = elements2;
      }
  
      public static void main(String[] a)
      {
          ArrayList&lt;Integer&gt; stuff = new ArrayList&lt;Integer&gt;();
          stuff.add(1);
          stuff.add(1);
          stuff.add(1);
          stuff.add(1);
  
          bugs b = new bugs(stuff);
          b.change(2, 999);
          b.reset();
  
          System.out.println(b.elements2);
      }
  }
  </code></pre>
  
  <p>This outputs:</p>
  
  <blockquote>
    <p>[1, 1, 999, 1]</p>
  </blockquote>
  
  <p>The second arraylist <code>elements2</code> is there to reset the arraylist <code>elements1</code> to its original position. However, for some reason <code>elements1</code> is being copied to <code>elements2</code>, printing </p>
  
  <blockquote>
    <p>[1, 1, 999, 1]</p>
  </blockquote>
  
  <p>and not</p>
  
  <blockquote>
    <p>[1, 1, 1, 1]</p>
  </blockquote>