Given this code in a method:
5. String s = "dogs. with words."; 6. // insert code here 7. for(String o: output) 8. System.out.print(o + " ");
Which of the following, inserted independently at line 6, will produce output that contains the String "dogs"? (Choose all that apply.).
C, D, and F are correct.
The "\\d" tells the split()
method to split Strings whenever a digit is encountered.
The "\\s" tells the split()
method to split Strings whenever a whitespace character is encountered.
Because a standalone "." (dot) is a predefined metacharacter (like \d or \s), the "\\." tells the split method to split Strings whenever the character "." is encountered.
A is incorrect because "s" characters are viewed as splitting characters and are removed from the output.
B is incorrect because "d" characters are viewed as splitting characters.
E is incorrect because the "\\w" tells the split()
method to use letters, digits, and the underscore character as splitting characters.