Java char value escape
In this chapter you will learn:
Description
The escape sequences are used to enter impossible-to-enter-directly characters.
Syntax
'\''
is for the single-quote character.
'\n'
is for the newline character.
Example
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 exactly four hexadecimal digits.
For example, '\u0061
' is the ISO-Latin-1
'a
' because the top byte is zero.
'\ua432
' is a Japanese Katakana character.
public class Main {
public static void main(String[] argv) {
char ch = '\'';
/*from w w w.j a va 2 s . c om*/
System.out.println("ch is " + ch);//ch is '
}
}
Character is a simple wrapper around a char.
The code above generates the following result.
Escape value list
The following table shows the character escape sequences.
Escape Sequence | Description |
---|---|
\ddd | Octal character (ddd) |
\uxxxx | Hexadecimal Unicode character (xxxx) |
\' | Single quote |
\" | Double quote |
\\ | Backslash |
\r | Carriage return |
\n | New line |
\f | Form feed |
\t | Tab |
\b | Backspace |
Next chapter...
What you will learn in the next chapter: