title: how to store array in a recursive function?
body: <p>I have a permutation recursive array which works fine but I need to store the result not just print them out,I have to store each print out in a separate array or the whole in one array </p>
  
  <p>here is the original:</p>
  
  <pre><code>public static void Permute(String soFar, String rest)  
          {  
             if (rest.isEmpty())  
             {
                 System.out.println(soFar);  
  
             }           
              else  
             {  
                 for (int i =0; i &lt; rest.length(); i++)  
                  {  
                      String next = soFar + rest.charAt(i);  
                      String remaining  = rest.substring(0,i) + rest.substring(i+1);  
                      Permute(next,remaining);  
                  }  
             }  
          }  
  </code></pre>
  
  <p>and I changed it but the problem is that return arr is not proper in there I should do something else
  because the arr would become empty because other recursive function would be called and I don't want it</p>
  
  <pre><code>public static String Permute(String soFar, String rest,String arr)  
      {  
         if (rest.isEmpty())  
         {
          //   System.out.println(soFar);  
         arr+=soFar;
         }           
          else  
         {  
             for (int i =0; i &lt; rest.length(); i++)  
              {  
                  String next = soFar + rest.charAt(i);  
                  String remaining  = rest.substring(0,i) + rest.substring(i+1);  
                  Permute(next,remaining,arr);  
              }  
         }  
      return arr;
      }  
  </code></pre>