Java Characters

tutorial and example
tutorial and example

JAVA CHARACTER

Normally, when we work with characters, we use primitive data types char. When we have to work with the objects of char, we use Character class.

Character class has many important method to manipulate characters.

Example:

char primitive is created by

Character object is created as

The compiler convert the char primitive type to Character object as required, like when we pass a char to a method and the method accept Character object then it convert it to character object.

Escape Sequences

(/) is called escape sequence and the compiler treats this character especially, it is used in different scenarios like:-

\t        It inserts a tab in the text at this point. It

\b       It inserts a backspace in the text at this point.

\n       It inserts a newline in the text at this point.

\r        It inserts a carriage return in the text at this point.

\f        It inserts a form feed in the text at this point.

\’         It inserts a single quote character in the text at this point.

\”        It inserts a double quote character in the text at this point.

\\        It inserts a backslash character in the text at this point.

Example:

Output:

Java Character Methods

isLetter() : It determines whether the specified char value is a letter.

isDigit() : It determines whether the specified char value is a digit.

IsWhitespace() : It determines whether the specified char value is white space.

IsUpperCase() : It determines whether the specified char value is uppercase.

isLowerCase() : It determines whether the specified char value is lowercase.

toUpperCase() : It returns the uppercase form of the specified char value.

toLowerCase() : It returns the lowercase form of the specified char value.

toString() : It returns a string object representing the specified character value that is, a one character string.