If I have a String variable containing a sentence, does anybody know how to extract the words from that sentence and store them in an array?
e.g. Take the String ("Hello World")
and store it like ["Hello","World"]
This is what I have been trying, but it doesn't work at all:
int newWord = 0;
String sentence;
String[] words;
for(count = 0; count < sentence.length(); count++)
{
words[newWord].charAt(count) = sentence.charAt(count);
if(sentence.charAt(count) == ' ' )
{
newWord++;
}
}
"Hello World".split(" ");