There are three classes in Java that are responsible for manipulating characters: Character, String, StringBuffer. Where the character class operates on a single character, string is an operation on a sequence of characters, and StringBuffer is the operation of a string of characters.
1. character's statement
Pubic final class Character extends Object implements Serializable,comparable<character>
2. The construction method of character
Public Character (char)
3. Common Methods
Some of the class methods in the character class are useful when working with strings, which can be used to classify characters, such as determining whether a character is a numeric character or changing a character case.
- public static Boolean isdigit (char ch) If CH is a numeric character method that returns true, otherwise returns false.
- public static Boolean isletter (char ch) If CH is the alphabetic method returns True, otherwise returns false.
- · public static Boolean isletterordigit (char ch) returns FALSE if Ch is a numeric character or the alphabetic method returns True.
- public static Boolean islowercase (char ch) If CH is a lowercase method returns True, otherwise returns false.
- public static Boolean isuppercase (char ch) If CH is the uppercase method returns TRUE, otherwise false is returned.
- public static char tolowercase (char ch) returns the lowercase form of ch.
- public static char touppercase (char ch) returns the uppercase form of Ch.
- public static Boolean Isspacechar (char ch) If CH is a space return true.
Public classCharactertest { Public Static voidMain (string[] args) {/** toString () method*/Character Ch=NewCharacter (' a ');//declaring a character class object and initializing itSystem.out.println ("This is a character:" +ch); String Str=ch.tostring (); System.out.println (str); System.out.println (The type of CH is: "+Ch.getclass ()); //output ch Object classString STRR = character.tostring (' C '); System.out.println (STRR); /** CompareTo Method*/Character ch1=NewCharacter (' a '); Character CH2=NewCharacter (' A '); intx =ch1; inty =CH2; System.out.println ("x=" + x + "" + "y=" +y); intt =Ch1.compareto (CH2); if(T = = 0) System.out.println (ch1+ "equals" +CH2); Else if(T < 0) System.out.println (ch1+ "less than" +CH2); Else if(T > 0) System.out.println (ch1+ "Greater than" +CH2); /** Isuppercase and Islowercase*/ CharCH3 = ' A '; CharCH4 = ' A '; BooleanB1 =Character.isuppercase (CH3); BooleanB2 =character.islowercase (CH4); if(B1 = =true) System.out.println (CH3+ "is uppercase characters"); ElseSystem.out.println (CH3+ "is lowercase characters"); if(B2 = =true) System.out.println (CH4+ "is lowercase characters"); ElseSystem.out.println (CH4+ "is uppercase characters"); /** Isletter Method*/Character Ch5= ' A '; Character Ch6= 64; System.out.println (Ch5+ "is a letter is" +Character.isletter (CH5)); System.out.println (Ch6+ "is a letter is" +Character.isletter (CH6)); }}
The output is:
This is a character: a
A
The type of CH is: class Java.lang.Character
C
x=97 y=65
A greater than a
A is lowercase characters
A is an uppercase character
A is a letter is true
@ is a letter is false
The Java_ character class (Character, String, StringBuffer) _char is the basic data type, and Character is its wrapper type.