title: Is the copy constructor of Java's ArrayList shallow copy or deep copy?
body: <p>I have long being confused with whether Java's container's copy constructor is shallow copy or deep copy?
  Below is my understanding:
  ints1, ints2, ints3 are references so they lie in stack.
  inst1 points to some object in heap, and this object holds three anonymous references that lie in stack, and they point to Objects that have int value 0, 1, 2 seperately.</p>
  
  <pre><code>ints2 = ints1
  </code></pre>
  
  <p>so ints2 points to the same object as ints1. So change objects pointed by refenences in ints2 will influence those in ints2.</p>
  
  <pre><code>ints2.set(1,0+10)
  </code></pre>
  
  <p>will change refenence ints1.get(0)'s object.</p>
  
  <pre><code>ints3 = new ArrayList&lt;&gt;(ints1)
  </code></pre>
  
  <p>Next is my confusion.</p>
  
  <p>If copy constructor is shallow copy, then although ints1 and ints3 point to different object, the two objects have same references! So any action to change objects by manipulating reference in ints1 will changes ints3, because they are pointing to the same objects.</p>
  
  <p>If copy constructor is deep copy, then ints1 and ints3 will hold different references and point to different objects. Then the change in ints1 will not influence that in ints3. </p>
  
  <p>According to the result, it seems that the copy constructor is deep copy, not shallow copy. </p>
  
  <p>Hope someone can correct me, thanks.</p>
  
  <pre><code>import java.util.*;
  public class MyClass {
      public static void main(String args[]) {
         List&lt;Integer&gt; ints1 = new ArrayList&lt;&gt;(Arrays.asList(0,1,2));
         System.out.println(ints1);
         List&lt;Integer&gt; ints2 = ints1;
         ints2.set(0,0+10);
         System.out.println(ints1);
         List&lt;Integer&gt; ints3 = new ArrayList&lt;&gt;(ints1);
         ints3.set(1,1+10);
         System.out.println(ints1);
      }
  }
  result
  [0, 1, 2]
  [10, 1, 2]
  [10, 1, 2]
  </code></pre>