Home > Java > javaTutorial > body text

Detailed explanation of examples of Character class

Y2J
Release: 2017-05-19 10:18:58
Original
3458 people have browsed it

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(&#39;2&#39;,2): " + Character.digit(&#39;2&#39;,2) ); 
System.out.println("Character.digit(&#39;7&#39;,10): " + Character.digit(&#39;7&#39;,10) ); 
System.out.println("Character.digit(&#39;F&#39;,16): " + Character.digit(&#39;F&#39;,16) );
Copy after login

The result is:

Character.MIN_RADIX: 2 
Character.MAX_RADIX: 36 
Character.digit(&#39;2&#39;,2): -1   不是有效值。
Character.digit(&#39;7&#39;,10): 7 
Character.digit(&#39;F&#39;,16): 15
Copy after login

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) );
Copy after login

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
Copy after login

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 = &#39;\u0009&#39;;//水平列表符 
   char c2 = &#39;\u000A&#39;;//换行 
   char c3 = &#39;\u000B&#39;;//垂直列表符 
   char c4 = &#39;\u000C&#39;;//换页 
   char c5 = &#39;\u000D&#39;;//回车 
   char c6 = &#39;\u
001
C&#39;;//文件分隔符 
   char c7 = &#39;\u001D&#39;;//组分隔符 
   char c8 = &#39;\u001E&#39;;//记录分隔符 
   char c9 = &#39;\u001F&#39;;//单元分隔符
Copy after login

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(&#39;q&#39;): " + Character.toUpperCase(&#39;q&#39;) );
System.out.println("Character.toLowerCaseCase(&#39;B&#39;): " + Character.toLowerCase(&#39;B&#39;) );
Copy after login

The result is:

Character.toUpperCase(&#39;q&#39;): Q 
Character.toLowerCaseCase(&#39;B&#39;): b
Copy after login

[Related recommendations]

1. Java Free Video Tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!