How do you split a line of words and keep spaces?
Here is the code:
String words[] = s.split(" ");
String s contains: hello world
After running the code, the words [] contain: "hello" "" world
Ideally, this should not be an empty string in the middle, but contain both spaces: the words [] should be: "hello" " " " " world
How do I get this result?
java regex
Rock lee
source share