Home Java javaTutorial Detailed explanation of examples of Character class

Detailed explanation of examples of Character class

May 19, 2017 am 10:18 AM

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

See all articles