Escape sequences are for characters that are impossible to enter directly.
To enter the single quote character itself, you 'escape' it by placing a backslash in front of it.
public class Main {
public static void main(String[] argv) {
char ch = '\'';
System.out.println("ch is " + ch);
}
}
The output generated by this program is shown here:
ch is '
The following table shows the character escape sequences.
Escape Sequence of Java char
Escape Sequence | Description |
---|---|
\ddd | Octal character (ddd) |
\uxxxx | Hexadecimal UNICODE character (xxxx) |
\' | Single quote |
\" | Double quote |
\\ | Backslash |
\r | Carriage return |
\n | New line (also known as line feed) |
\f | Form feed |
\t | Tab |
\b | Backspace |
'\n' is for the newline character. For octal notation use the backslash followed by the three-digit number. For example, '\141' is the letter 'a'. For hexadecimal, you enter a backslash-u (\u), then four hexadecimal digits. For example, '\u0061' is the ISO-Latin-1 'a'.
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |