title: ArrayList of ArrayLists - clear function confusion
body: <p>Here is a particular method I have written:  </p>
  
  <pre><code>class A {
  
      private static ArrayList&lt;ArrayList&lt;Integer&gt;&gt; inputTerms = new ArrayList&lt;ArrayList&lt;Integer&gt;();
  
      public static void method1(ArrayList&lt;Integer&gt; terms) {
          ArrayList&lt;Integer&gt; clauses = new ArrayList&lt;Integer&gt;();
          int N = terms.size();
          for (int i = 0; i &lt; N - 1; i++) {
              for (int j = i + 1; j &lt; N; j++) {
                  clauses.add(-terms.get(i));
                  clauses.add(-terms.get(j));
                  inputTerms.add(clauses);
                  clauses.clear();
              }
          }
      }
  }
  </code></pre>
  
  <p>This method is called multiple times from the main function.
  In the end, i try to write the contents of the class variable into a file. However, when I do this, i get 0 as the contents of inputTerms. However, if i remove the clauses.clear() line, i am able to get approppriate values.</p>
  
  <p>My program is such that it is vital for me to clear the clauses after adding to inputTerms. Is there any alternative to this?</p>
  
  <p>**Hmmm.. I have done what you've suggested. However, I haven't quite overcome the problem. To give more background, in my main function, I have the following code: </p>
  
  <pre><code>for (int i=0; i&lt;N-1; i++){ 
  ArrayList&lt;Integer&gt; firstdiagonalTerms = new ArrayList&lt;Integer&gt;(); 
  for (int j=0; j&lt;N-i; j++){ 
  firstdiagonalTerms.add(variable[j][i+j]); 
  } 
  method1(firstdiagonalTerms);
  } 
  </code></pre>
  
  <p>I have to call the method1 function 4 times for different combinations of 'i' and 'j'. However, I still get 0 when I use the above mentioned suggestions**</p>