Characters of Java

Source: Internet
Author: User

Reference http://how2j.cn/k/number-string/number-string-character/323.html

Char is used when saving a character
Package character; Public classTestchar { Public Static voidMain (string[] args) {CharC1 ='a'; CharC2 ='1';//character 1, not number 1        CharC3 ='in';//Kanji Characters//CharC4 ='AB';//Error,only one character can be placed             }}
Package class for Char

The wrapper class for Char is character

 Public class Testchar {     publicstaticvoid  main (string[] args) {        Char  'a';         // Automatic Boxing        C1 = C; // Automatic Unpacking              }}
Character Common methods
Package character; Public classTestchar { Public Static voidMain (string[] args) {System. out. println (Character.isletter ('a'));//determine if it is a letterSystem. out. println (Character.isdigit ('a'));//determine whether a numberSystem. out. println (Character.iswhitespace (' '));//whether it is blankSystem. out. println (Character.isuppercase ('a'));//whether it is uppercaseSystem. out. println (Character.islowercase ('a'));//whether it is lowercaseSystem. out. println (Character.touppercase ('a'));//Convert to uppercaseSystem. out. println (Character.tolowercase ('A'));//Convert to lowercase
String a = ' a '; Cannot directly convert a character to a string
    String A2 = Character. toString (//Convert to String
System. out.println ("a2=" +a2);

Char c=' a ';
String A3=character. valueOf (c). ToString ();
System. out.println ("a3=" +a3);
} }

Execution results

Common escapes
Package character;  Public classTestchar { Public Static voidMain (string[] args) {System. out. println ("the use of spaces does not achieve the effect of alignment"); System. out. println ("ABC def"); System. out. println ("AB def"); System. out. println ("a def"); System. out. println ("use \\t tabs to achieve alignment effects"); System. out. println ("Abc\tdef"); System. out. println ("Ab\tdef"); System. out. println ("A\tdef"); System. out. println ("a \\t tab length is 8"); System. out. println ("12345678def"); System. out. println ("line break \\n"); System. out. println ("Abc\ndef"); System. out. println ("single quote \ \ '"); System. out. println ("abc\ ' def"); System. out. println ("Double quote \\\ ""); System. out. println ("abc\ "Def"); System. out. println ("The backslash itself \ \"); System. out. println ("Abc\\def"); }}

Execution results

Characters of Java

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.