In this post, we discuss the character class in java.
Example:
char ch = 'x'; // Unicode for uppercase Greek omega character char uniChar = '\u039A'; // an array of chars char[] charArray ={ 'x', 'y', 'z' };
Java provides wrapper class Character for primitive data type char. You can create a Character object with the Character constructor:
Character ch = new Character('x');
Escape Sequences
A character preceded by a backslash (\) is an escape sequence and has a special meaning to the compiler. The newline character (\n) has been used frequently in this tutorial in System.out.println() statements to advance to the next line after the string is printed.
Escape Sequence | Description |
---|---|
\t | Use to Inserts a tab in the text at this point. |
\n | Use to Inserts a newline in the text at this point. |
\f | Use to Inserts a form feed in the text at this point. |
\r | Use to Inserts a carriage return in the text at this point. |
\” | Use to Inserts a double quote character in the text at this point. |
\’ | Use to Inserts a single quote character in the text at this point. |
\\ | Use to Inserts a backslash character in the text at this point. |
Example
use the escape sequence, \”, on the interior quotes:
public class Test { public static void main(String args[]) { System.out.println("Hello \"World\" !"); } }
Output
Hello "World" !
Character Methods
Following is the list of the important instance methods that all the subclasses of the Character class implement −
Method | Description |
---|---|
isLetter() | This method Determines whether the specified char(ch) value is a letter.. |
isDigit() | This method Determines whether the specified char(ch) value is a digit. |
isWhitespace() | This method Determines whether the specified char value is white space. |
isUpperCase() | This method Determines whether the specified char(ch) value is uppercase. |
isLowerCase() | This method Determines whether the specified char(ch) value is lowercase. |
toString() | Returns a String object representing the specified character value that is, a one-character string. |
Following is the list of the important instance methods that all the subclasses of the Character class implement −