Page 724 - AP Computer Science A, 7th edition
P. 724
you get the position of the blank in the original sentence.
• Part (b) takes advantage of the precondition that there is one and only one blank between words. This means that the number of words will always be the number of blanks plus one.
• In part (c), you have to be careful when you get the first word. If there’s only one word in the sentence, there are no blanks, which means posList is empty, and you can’t use posList.get(0) (because that will throw an IndexOutOfBoundsException!).
• Also in part (c), the second test deals with getting the last word in the sentence. You have to distinguish between the cases of more than one word in the sentence and exactly one word in the sentence.