This content has been marked as final. Show 3 replies
The problem is that it is doing it all on one line. Does this make more sense?
String sentence = " one two three "; String trimmedSentence = sentence.trim(); String words = trimmedSentence.split(" "); int numberOfWords = words.length;
Thank you. Separating it does make it quite a bit clearer. Your reply gave me another question though :p. Do you have to make your string into an array of words when you split it (I'm assuming that's what it's doing. We haven't covered arrays in my class yet so I'm not very familiar with them).
The return type of the split method is an array of Strings. So if you call that method you have no choice but to create an array.