[Solved] How can I form combinations out of a sentence


I think you could do something like:

    String[] words=title.split(" ");
    String printWord = "";
    for (int i = 0; i < words.length; i++) {
        printWord += words[i] + " "; // Add the space for newly appended words
        System.out.println(printWord);
    }

The above, will just print the following

The 
The amazing 
The amazing spider 
The amazing spider man 
The amazing spider man returns 

If you want to store it, just add it to a new array instead of calling System.out.println().

Edit: Removed the quotes in the returned strings, because it doesn’t print the quotes, of course 😛

Edit2: If you want to add it to an array without the trailing white-space, just use String.trim() as you add to the array.

solved How can I form combinations out of a sentence