title: Recursive method to generate all partitions of a String
body: <p>I am trying to solve this problem with the <code>partitioning</code> of a <code>String</code>. Let's take "abc" for example.<br>
  There are 4 <code>partitions</code> - <code>{a,bc}, {ab,c}, {abc}, {a,b,c}.</code><br>
  I am trying to write a <code>recursive</code> method to generate the <code>partitions</code> to an <code>ArrayList</code> of <code>Lists</code> but I struggle to do so. Help would be greatly appreciated!</p>
  
  <pre><code>static List&lt;List&lt;String&gt;&gt; partitions = new ArrayList&lt;&gt;();
  static List&lt;String&gt; partition = new ArrayList&lt;&gt;();
  
  static void recurse(int size, String str) {
      if (str.length() &lt;= size) {
          return;
      }
      partition.add(str.substring(0, size));
      for (int i = 1; i &lt; str.length(); i++) {
          if (size &lt; str.length())
              recurse(i, str.substring(size));
      }
      partitions.add(partition);
  }
  </code></pre>
  
  <p>Now when i call this method it outputs </p>
  
  <pre><code>[[, a, b, ab], [, a, b, ab], [, a, b, ab], [, a, b, ab]]
  </code></pre>
  
  <p>instead of <code>[[a, b, c], [a, bc], [ab, c], [abc]]</code></p>
  
  <p>, so i must be doing something wrong:</p>
  
  <pre><code>recurse(0, "abc");
      System.out.println(partitions.toString());
  </code></pre>