title: How to save as ArrayList<String>, all possible combinations of a set of characters in string?
body: <p>How can I save as an ArrayList all possible combinations of a set of characters in string?</p>
  
  <p>You can see my code below. It only print the combinations, but doesn't save all combinations. Any idea?</p>
  
  <pre><code>public class All_Possible_Combinatons 
  {
  
  static String combinations(char[] sequence, char[] data, int start, int end,
          int index, int r) 
  {   
  
      if (index == r) 
      {
          for (int j = 0; j &lt; r; j++)
              // = data[j];
              System.out.print(data[j] + " ");
          System.out.println();
      }
  
      for (int i = start; i &lt;= end &amp;&amp; ((end - i + 1) &gt;= (r - index)); i++) 
      {
          data[index] = sequence[i];
          combinations(sequence, data, i + 1, end, index + 1, r);
      }
      return null;
  
  }
  
  public static void main(String args[]) 
  {
      char[] sequence = { '0','1','2'/*,'3','4','5','6','7','8','9',':',';','&lt;','=','&gt;','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[',']','^','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' */};
      System.out.print("The combinations are: ");
  
  
    // printCombinations(sequence, sequence.length);
  
      int N=sequence.length;
      char[] data = new char[N];
      for (int r = 0; r &lt; sequence.length; r++)
          combinations(sequence, data, 0, N - 1, 0, r);
  }
  </code></pre>