Character class operation for a single character.
Character classes in a package base object type char value
Examples
char CH = 'A' ; // the Unicode character representation of char unichar = '\ u039A' ; // character array char [] = {charArray 'A', 'B', 'C', 'D', 'E' };
However, in the actual development process, we often encounter situations require the use of objects instead of the built-in data types. To solve this problem, Java language provides a wrapper class Character classes for built-in data type char.
Character class provides a series of methods to manipulate character. You can create an object using the Character class constructor Character, for example:
Character ch = new Character('a');
In some cases, Java compiler will automatically create a Character object.
For example, to pass a parameter of type char Character type parameter in need of a method, the compiler will automatically convert char Character type parameter to the object. This feature is called packing, unpacking in turn called.
Examples
// original character 'a' ch packing objects in the Character Character ch = 'a' ; // original character 'x' with the test method of packing // value returned to the unpacking 'C' char C = test ( ' x ');
Escape Sequences
Preceded by a backslash (\) character represents the escape character, it is the compiler has a special meaning.
The following list shows the Java escape sequences:
Escape Sequences | description |
---|---|
\t | In the text where the tab is inserted into a |
\b | In the text where the key is inserted into a retracted |
\n | Where in the text wrap |
\r | Where the carriage returns in the text |
\f | In the text where the insert page breaks |
\' | Inserted in the text where the single quote |
\" | Inserted in the text where the double quotes |
\\ | Inserted in the text where the backslash |
Examples
When the print statement encounters an escape sequence, the compiler can be correctly interpreted.
The following Examples and outputs escape double quotes:
Test.java file code:
public class the Test { public static void main (String args []) { System.out.println ( "access \" novice Tutorial \ "!" ); } }
The above examples compiled results are as follows:
Access "rookie Tutorial!"
Character method
Here's how the Character class:
No. | Method and Description |
---|---|
1 | isLetter () whether it is a letter |
2 | isDigit () whether a numeric character |
3 | isWhitespace () whether it is a blank character |
4 | isUpperCase () whether uppercase |
5 | isLowerCase () whether lowercase letters |
6 | toUpperCase () uppercase letters specified |
7 | the toLowerCase () specify a letter lowercase |
8 | toString () Returns a string of characters, the length of the string 1 is only |
For a complete list of methods, see the java.lang.Character API specification.