Java. How can I split a string with multiple spaces on every nth space?

java, string

Solution

You could do:

String[] stringArray = string.split("(?<!\\G\\S+)\\s");

Problem

Here's a sample string which I intend to split into an array: ``` Hello My Name Is The Mighty Llama ``` The output should be: ``` Hello My Name Is The Mighty Llama ``` The below splits on every space, how can I split on every other space? ``` String[] stringArray = string.split("\\s"); ```

Original source

Related problems