title: JAVA, list of lists
body: <p>I have list and list of lists:</p>
  
  <pre><code>ArrayList&lt;String&gt; singleList = new ArrayList&lt;String&gt;();
  ArrayList&lt;ArrayList&lt;String&gt;&gt; listOfLists = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
  </code></pre>
  
  <p>I do not understand the behavior of these lists. I decided to show you a simple example:</p>
  
  <pre><code>listOfLists.clear();
  
  singleList.clear();
  singleList.add("A");
  singleList.add("B");
  singleList.add("C");
  listOfLists.add(singleList);
  
  singleList.clear();
  singleList.add("D");
  singleList.add("E");
  singleList.add("F");
  listOfLists.add(singleList);
  
  singleList.clear();
  singleList.add("G");
  singleList.add("H");
  singleList.add("I");
  listOfLists.add(singleList);
  
  for(int x = 0; x &lt; listOfLists.size(); x++)
  {
      for(int z = 0; z &lt; singleList.size(); z++)
          {
          System.out.print(listOfLists.get(x).get(z));
          System.out.print(" ");
      }
      System.out.println("");
  }
  </code></pre>
  
  <p>And the result I got was:</p>
  
  <p>G H I 
  G H I 
  G H I </p>
  
  <p>Instead:</p>
  
  <p>A B C
  D E F
  G H I</p>
  
  <p>Where is a problem with my thinking? What should I do to get result as above?</p>