The Java string escapes are listed in Table 3-1.
Table 3-1. String escapes
To get: |
Use this: |
Notes |
---|---|---|
Tab |
| |
Linefeed (Unix newline) |
|
See |
Carriage return |
| |
Form feed |
| |
Backspace |
| |
Single quote |
| |
Double quote |
| |
Unicode character |
|
Four hexadecimal digits (no |
Octal(!) character |
|
Who uses octal (base 8) these days? |
Backslash |
|
Here is a code example that shows most of these in action:
// StringEscapes.java System.out.println("Java Strings in action:"); // System.out.println("An alarm or alert: a"); // not supported System.out.println("An alarm entered in Octal: 07"); System.out.println("A tab key: (what comes after)"); System.out.println("A newline: (what comes after)"); System.out.println("A UniCode character: u0207"); System.out.println("A backslash character: \");
If you have a lot of non-ASCII characters to enter, you may wish to consider using Java’s input methods, discussed briefly in the JDK online documentation.
18.117.230.81