title: Adding element to 2d arraylist in java
body: <pre><code>ArrayList&lt;Integer&gt; a =new ArrayList&lt;Integer&gt;();
  ArrayList&lt;ArrayList&lt;Integer&gt;&gt; j =new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();
  
  a.add(1);
  a.add(2);
  a.add(3);
  
  for(int c=0; c&lt;10; c++){
      j.add(a);
  }
  j.get(3).add(1);
  System.out.println(j);
  </code></pre>
  
  <p>Does anyone know why this code adds 1 to every element of j as opposed to only the third element, and what can I do to fix this?</p>