Java Character class
The Character class is used to manipulate individual characters
The Character class wraps the value of a base type char in an object
public class Test{ public static void main(String[] args){ char ch = ‘A‘; char uniChar = ‘\u039A‘;// Unicode 字符表示形式 char[] charArr = {‘A‘,‘B‘,‘C‘,‘D‘,‘E‘};// 字符数组 System.out.println(ch); System.out.println(uniChar); System.out.println(charArr); }}输出结果:AΚABCDE
In real-world development, you often encounter situations where you need to use objects that are not built-in data types.
The Character class provides a series of method manipulation characters that can be used to create Character class objects using the Character construction method.
Character ch = new Character(‘a‘);Character ch = ‘a‘;// 原始字符 ‘a‘ 装箱到 Character 对象 ch 中
Escape sequences
| Escape Sequences |
Description |
| \ t |
Insert a TAB key in the text |
| \b |
Insert a back key in the text |
| \ n |
The line wraps in the text. |
| \ r |
Insert a carriage return at this point in the text |
| \f |
Insert a page break at this point in the text |
| \‘ |
Insert single quotation marks at the same place in the text |
| \" |
Insert double quotation marks at this point in the text |
| \ |
Inserts a backslash in the text |
public class Test{ public static void main(String[] args){ System.out.println("1访问\t策略星官网"); System.out.println("2访问\b策略星官网"); System.out.println("3访问\n策略星官网"); System.out.println("访问\r策略星官网4"); System.out.println("5访问\f策略星官网"); System.out.println("6访问\\策略星官网\\"); System.out.println("7访问\‘策略星官网\‘"); System.out.println("8访问\"策略星官网\""); }}1访问 策略星官网2访策略星官网3访问策略星官网策略星官网45访问?策略星官网(换页符)6访问\策略星官网7访问‘策略星官网‘8访问"策略星官网"
Methods of the character class:
class a{int A = 133; Public String toString () {return (A + "I"); }}public class test{public static void Main (string[] args) {System.out.println ("Determines whether 5 is a letter:" + character.isletter (' 5 ')); SYSTEM.OUT.PRINTLN ("Determine if A is a letter:" + character.isletter (' a ')); System.out.println ("Judging whether 9 is a number:" + character.isdigit (' 9 ')); System.out.println ("Judging whether B is a number:" + character.isdigit (' B ')); System.out.println ("Judging whether it is a space:" + character.iswhitespace (')); SYSTEM.OUT.PRINTLN ("Determine if \ n is a space:" + character.iswhitespace (' \ n ')); SYSTEM.OUT.PRINTLN ("Determine if C is a space:" + character.iswhitespace (' C ')); SYSTEM.OUT.PRINTLN ("Determine if D is uppercase:" + character.isuppercase (' d ')); SYSTEM.OUT.PRINTLN ("Determine if D is uppercase:" + character.isuppercase (' d ')); SYSTEM.OUT.PRINTLN ("Determine if D is lowercase:" + character.islowercase (' d ')); SYSTEM.OUT.PRINTLN ("Determine if D is lowercase:" + character.islowercase (' d ')); SYSTEM.OUT.PRINTLN ("Specifies the uppercase form of the letter F:" + character.touppercase (' f ')); SYSTEM.OUT.PRINTLN ("Specifies the uppercase form of the letter F:" + character.touppercase (' f ')); SYSTEM.OUT.PRINTLN ("Specifies the lowercase form of the letter G:" + character.tolowercase (' G ')); SYSTEM.OUT.PRINTLN ("Specifies the lowercase form of the letter G:" + character.tolowercase (' G ')); System.out.println (character.tostring (' h ')); System.out.println (character.tostring (' H ')); A x = new A (); System.out.println (X.tostring ()); }} to determine whether 5 is a letter: false to determine whether a is a letter: true to determine whether 9 is a number: True to determine whether B is a number: false to judge is a space: true to determine if C is a space: false to determine if D is a capital letter: False to determine if D is uppercase: True to determine if D is lowercase: true to determine if D is lowercase: false to specify the uppercase form of the letter F: f Specifies the uppercase form of the letter F: f Specifies the lowercase form of the letter G: g Specifies the lowercase form of the letter G: ghh133i
Organizing Java Basics--character class