Small Word Filter With Array
Write a method called smallWordFilter that, given a non-null String containing words separated by single spaces
(" "), returns all the words in the original String that are 3 characters or shorter in the same order in
which they appeared in the original String, as a String[].
For example, given the input "Xyz is the very best cat" you would return the String[] {"Xyz", "is", "the",
"cat"}.
We have skipped both "very" and "best" because they are longer than 3 characters.
This is a problem that would be much easier to solve using a list, since you don't know exactly how many part of
the input String are 3 characters or smaller!
But this can be done with an array, if somewhat awkwardly.
Here's a solution sketch to help you get started:
- Split the array based on the single space
" " - Next, count the number of parts of the
Stringthat are 3 characters or smaller - Now create your
String[]of the appropriate size - And then loop again through the array of
Stringparts filling your output array as you go
We've provided some starter code to help you get going on this problem.