title: Recursively create objects
body: <p>I'm trying run my method recursively. In each iteration of method I create new <code>ArrayList</code> and fill it some values and check some condition in <code>if</code> operator. If it's true, will run this method again. If it's false, I want exit of current iteration of method and work in previous iteration of method with previous copy of <code>ArrayList</code>. In practice, when I get false in condition and go in previous iteration of my method, I work with same <code>ArrayList</code>. And it's bad.</p>
  
  <p>How do I create each instance of <code>ArrayList</code> for each iteration of method and when follow back in previous method work with instance of that iteration of <code>ArrayList</code>?</p>
  
  <p>My code:</p>
  
  <pre><code>    private List&lt;List&lt;String&gt;&gt; letsTry(List&lt;List&lt;ProbableValue&gt;&gt;
  probableValues, List&lt;List&lt;String&gt;&gt; data) {
  
       List&lt;List&lt;String&gt;&gt; copyOfData = new ArrayList&lt;List&lt;String&gt;&gt;(data);
       List&lt;List&lt;ProbableValue&gt;&gt; copyOfProbableValues = 
                             new ArrayList&lt;List&lt;ProbableValue&gt;&gt;(probableValues);
  
      ProbableValue minPV = getMinPV(copyOfProbableValues);
  
      Set&lt;String&gt; pValues = new HashSet&lt;String&gt;(minPV.getProbableValues());
      int i = minPV.getI();
      int j = minPV.getJ();
  
  
      for (String v : pValues) {
  
          if (checker.canSetOnTable(copyOfProbableValues, minPV)) {
              if (!SUtils.isItsNumber(copyOfData.get(i).get(j))) {
                  copyOfData.get(i).set(j, v);
  
            copyOfProbableValues.get(i).get(j).getProbableValues().clear();
            checker.removeProbableValue(copyOfProbableValues, v, i, j);
  
              }
            letsTry(new ArrayList&lt;List&lt;ProbableValue&gt;&gt;(copyOfProbableValues),
                      new ArrayList&lt;List&lt;String&gt;&gt;(copyOfData));
  
          }
  
      }
  
      return copyOfData;
  
  }
  </code></pre>