This Java tutorial shows how to split a string into multiple words.
In Java 1.4, Sun added a split() method to the String class. The split method allows you to specify a regular expression that is used to split the string into a string array. To split a string where there words are separated by a space, simply specify a space (" ") as the parameter to the split() method.
The following code example shows how to split a sentence into words:
String sentence = "This is a sentence.";Below is output from the example code:
String words = sentence.split(" ");
for (String word : words)