Given:
51. String s = "4.5x8.a.3"; 52. String[] tokens = s.split("\\s"); 53. for(String o: tokens) 54. System.out.print(o + " "); 55. 56. System.out.print(" "); 57. tokens = s.split("\\.."); 58. for(String o: tokens) 59. System.out.print(o + " ");
What is the result?
E is correct.
The first invocation of split()
uses the "\s" metacharacter, which splits on whitespace.
Since there is no whitespace in String s, the entire string is placed into tokens[0].
The second invocation of split()
combines "\\." (which means look for "."), with a standalone ".", which is the metacharacter for "find any character."
So the second split()
reads "split on a dot followed by any character."
Note that the split()
method does not change the String being split.