What is the result?

Given:

11. String test = “This is a test”;
12. String[] tokens = test.split(“\s”);
13. System.out.println(tokens.length);

What is the result?

Given:

11. String test = “This is a test”;
12. String[] tokens = test.split(“\s”);
13. System.out.println(tokens.length);

What is the result?

A.
0

B.
1

C.
4

D.
Compilation fails.

E.
An exception is thrown at runtime.

Explanation:
Main.java:12: illegal escape character
String[] tokens = test.split(“\s”);
^
1 error



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Anuja Das

Anuja Das

Answer is D, since \s is an invalid escape sequence.