title: All Combinations of sub-strings in a sentence in java
body: <p>I need to find the combinations of words in a space separated string . Suppose the String is "I will go" then the output will be - </p>
  
  <ol>
  <li>I, will, go</li>
  <li>I, will go</li>
  <li>I will, go</li>
  </ol>
  
  <p>String may be bigger. 
  I tried but stuck. Would you please help me to resolve the issue.
  Thanks in advance. </p>
  
  <pre><code>public class Combination_Of_Words_In_Sentence {
  
  public static void main(String[] args) {
      String inputString = "I will go";
      String[] arrString = inputString.split(" ");
      printString(arrString);
  }
  
  private static void printString(String[] arrString) {
      int len = arrString.length;
      String[] arr = new String[len];
  
      for(int i=0;i&lt;arrString.length;i++){
          for(int j=0;j&lt;i+1;j++){
              arr[i] = arrString[j]+" ";
              System.out.println();
          }
          arr[i] +=",";
          printPatternUtil(arrString, arr, 1, 1, len);
      }   
  }
  
  private static void printPatternUtil(String[] arrString, String[] arr,
          int i, int j, int n) {
      if(i == n){
          // arr[j] = " ";
           for(int k=0;k&lt;arr.length;k++)
           System.out.print(arr[k]);
  
           System.out.println();
              return;
      }
      arr[j] = arrString[i]+",";
      printPatternUtil(arrString, arr, i+1, j+1, n) ;
  
      // Or put a space followed by next character
     // arr[j] = ",";
      //arr[j+1] = arrString[i]+ " ";
  
     // printPatternUtil(arrString, arr, i+1, j+2, n);
  
  }
  
  }
  </code></pre>