The Java_ character class (Character, String, StringBuffer) _char is the basic data type, and Character is its wrapper type.

Source: Internet
Author: User
Tags uppercase character

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.

    1. public static Boolean isdigit (char ch) If CH is a numeric character method that returns true, otherwise returns false.
    2. public static Boolean isletter (char ch) If CH is the alphabetic method returns True, otherwise returns false.
    3. · public static Boolean isletterordigit (char ch) returns FALSE if Ch is a numeric character or the alphabetic method returns True.
    4. public static Boolean islowercase (char ch) If CH is a lowercase method returns True, otherwise returns false.
    5. public static Boolean isuppercase (char ch) If CH is the uppercase method returns TRUE, otherwise false is returned.
    6. public static char tolowercase (char ch) returns the lowercase form of ch.
    7. public static char touppercase (char ch) returns the uppercase form of Ch.
    8. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.