March 2019
Intermediate to advanced
242 pages
6h 21m
English
By default, the raw string literals don't interpret the escape sequences. However, what if you want them to do so? When used with a raw string, the unescape() method will match the sequence of the characters following \ with the sequence of Unicode escapes and escape sequences, as defined in the Java Language Specifications (JLS). If a match is found, the escape sequence will not be used as a regular combination of letters; it will be used as an escape sequence.
The following code doesn't interpret \n as a newline escape sequence:
System.out.print("eJava");
System.out.print("\\n");
System.out.print("Guru");
The output of the preceding code is as follows:
eJava\nGuru
However, the following code will interpret \n as ...
Read now
Unlock full access