Character literals provide the most convenient way to express char
values in Java source code. A character literal consists of:
'
) character.\
) character; see Escape sequences in literals.'
) 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