How to use the Character class
Character: Character type
1, attributes.
static int MIN_RADIX: Returns the minimum radix.
static int MAX_RADIX: Returns the maximum radix.
static char MAX_VALUE: The maximum value of character type.
static char MIN_VALUE: Minimum value of character type.
static Class TYPE: Returns the current type.
2、Constructor.
Character(char value): Construct a Character object with char parameters.
3. Method.
Instructions:
1. All methods are public;
2. Writing format: [Modifier]
Such as :
static int parseInt(String s) means: This method (parseInt) is a class method (static), the return type is (int), and the parameters required by the method are of type String.
1. char charValue(): Returns the value of the character object.
2. int compareTo(Character anotherCharacter): Compare the current Character object with anotherCharacter. The equality relationship returns 0; the less than relationship returns a negative number; the greater than relationship returns a positive number.
3. int compareTo(Object o): Compare the current object with another object. If o is a Character object, it has the same function as 2; otherwise, a ClassCastException is thrown.
4. static int digit(char ch, int radix): Returns the decimal value of the current character according to the base. If Character.MIN_RADIX <= radix <= Character.MAX_RADIX is not satisfied, or ch is not a valid value in the radix base, return "-1"; if ch is between "uppercase" A and Z, return ch - The value of 'A' + 10; if it is "lowercase" between a and z, return ch - the value of 'a' + 10.
Code:
System.out. print ln("Character.MIN_RADIX: " + Character.MIN_RADIX ); System.out.println("Character.MAX_RADIX: " + Character.MAX_RADIX ); System.out.println("Character.digit('2',2): " + Character.digit('2',2) ); System.out.println("Character.digit('7',10): " + Character.digit('7',10) ); System.out.println("Character.digit('F',16): " + Character.digit('F',16) );
The result is:
Character.MIN_RADIX: 2 Character.MAX_RADIX: 36 Character.digit('2',2): -1 不是有效值。 Character.digit('7',10): 7 Character.digit('F',16): 15
5. boolean equals(Object obj): Compare with objobject. Returns "true" if and only if obj is not "null" and is consistent with the current Character
object.
6. static char forDigit(int digit, int radix): Determine the character represented by the current value based on a specific base. The inverse operation of 4, returns "'\u0000'" if the value is illegal.
Code:
System.out.println("Character.MIN_RADIX: " + Character.MIN_RADIX ); System.out.println("Character.MAX_RADIX: " + Character.MAX_RADIX ); System.out.println("Character. for Digit(2,2): " + Character.forDigit(2,2) ); System.out.println("Character.forDigit(7,10): " + Character.forDigit(7,10) ); System.out.println("Character.forDigit(15,16): " + Character.forDigit(15,16) );
The result is:
Character.MIN_RADIX: 2 Character.MAX_RADIX: 36 Character.forDigit(2,2): Character.forDigit(7,10): 7 Character.forDigit(15,16): f
7. static int getNumericValue(char ch): Returns the numerical value of character ch.
8. static int getType(char ch): Returns the type of character. Please check the Java documentation for specific types.
9. int hashCode(): Returns the hash table code of the current character.
10. static boolean isDefined(char ch): Determine whether the character ch is clearly defined in the Unicode character set.
11. static boolean isDigit(char ch): Determine whether the character ch is a number.
12. static boolean isIdentifierIgnorable(char ch): Determine whether the character ch is an ignorable character in the Unicode character set.
13. static boolean isISOControl(char ch): Determine whether the character ch is a control character in the ISO standard.
14.static boolean isJavaIdentifierPart(char ch): Determine whether the character ch is a partial identifier in Java.
15. static boolean isJavaIdentifierStart(char ch): Determine whether the character ch is the first identifier in Java.
16. static boolean isLetter(char ch): Determine whether the character ch is a letter.
17. static boolean isLetterOrDigit(char ch): Determine whether the character ch is a letter or number.
18. static boolean isLowerCase(char ch): Determine whether the character ch is a lowercase letter.
19. static boolean isMirrored(char c): Determine whether the character c has a character in the opposite direction according to the Unicode table. For example: "[" has "]" in the opposite direction, and the result is: true.
20. static boolean isSpaceChar(char ch): Determine whether the character ch is a space in Unicode.
21. static boolean isUpperCase(char ch): Determine whether the character ch is an uppercase letter.
22. static boolean isWhitespace(char ch): Determine whether the character ch is a null character in Java definition.
Code:
Including:
char c1 = '\u0009';//水平列表符 char c2 = '\u000A';//换行 char c3 = '\u000B';//垂直列表符 char c4 = '\u000C';//换页 char c5 = '\u000D';//回车 char c6 = '\u 001 C';//文件分隔符 char c7 = '\u001D';//组分隔符 char c8 = '\u001E';//记录分隔符 char c9 = '\u001F';//单元分隔符
23. static char toLowerCase(char ch): Convert whether ch is lowercase.
24. String toString(): Convert the current Character object into a string.
25. static String toString(char c): This is a class method that converts c into a string.
26. static char toUpperCase(char ch): Convert whether ch is uppercase.
Code:
System.out.println("Character.toUpperCase('q'): " + Character.toUpperCase('q') ); System.out.println("Character.toLowerCaseCase('B'): " + Character.toLowerCase('B') );
The result is:
Character.toUpperCase('q'): Q Character.toLowerCaseCase('B'): b
[Related recommendations]
2. Detailed explanation of the differences between Character and char methods
3. Explain in detail the Character class in Java
4. Instance analysis of the packaging class Character
5. About the usage analysis of Character class
The above is the detailed content of Detailed explanation of examples of Character class. For more information, please follow other related articles on the PHP Chinese website!