Character literals
suggest changeCharacter literals provide the most convenient way to express char
values in Java source code. A character literal consists of:
- An opening single-quote (
\'
) character. - A representation of a character. This representation cannot be a single-quote or a line-break character, but it can be an escape sequence introduced by a backslash (
\\
) character; see Escape sequences in literals. - A closing single-quote (
\'
) character.
For example:
char a = 'a';
char doubleQuote = '"';
char singleQuote = '\'';
A line-break in a character literal is a compilation error:
char newline = '
// Compilation error in previous line
char newLine = '\n'; // Correct
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents