This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

Writing in the front

Today we are going to learn about the use of the Character class in Java, mainly the use of some of the methods, because recently used more frequently, hereby sort out, share with you, if you have any better knowledge, you can share in the comments section.

The Character class is a class that does some judgment, processing, and manipulation on a single Character. Some of the methods are very useful.

Some methods in the Character class

If you’re new to the Character class, some of these methods will look familiar.


Methods: isLetter

Description: Checks whether the current character is a letter.

Specific use:

char a = 'a';
char b = '1';
System.out.println(Character.isLetter(a));
System.out.println(Character.isLetter(b));
Copy the code

Running results:

true
false
Copy the code

Methods: isDigit

Description: Checks whether the current character is a number.

Specific use:

char a = 'a';
char b = '1';
System.out.println(Character.isDigit(a));
System.out.println(Character.isDigit(b));
Copy the code

Running results:

false
true
Copy the code

Methods: isWhitespace

Description: Checks whether the current character is a blank character.

Specific use:

char a = 'a';
char b = '1';
char c = ' ';
System.out.println(Character.isWhitespace(a));
System.out.println(Character.isWhitespace(b));
System.out.println(Character.isWhitespace(c));
Copy the code

Running results:

false
false
true
Copy the code

Methods: isUpperCase

Description: Checks if the current character is an uppercase letter, even if it is a number, but only returns false.

Specific use:

char a = 'a';
char b = '1';
char c = 'A';
System.out.println(Character.isUpperCase(a));
System.out.println(Character.isUpperCase(b));
System.out.println(Character.isUpperCase(c));
Copy the code

Running results:

false
false
true
Copy the code

Methods: isLowerCase

Description: If the current character is a lowercase character, the same method is used to determine whether the character is a lowercase character.

Specific use:

char a = 'a';
char b = '1';
char c = 'A';
System.out.println(Character.isLowerCase(a));
System.out.println(Character.isLowerCase(b));
System.out.println(Character.isLowerCase(c));
Copy the code

Running results:

true
false
false
Copy the code

Methods: the toUpperCase

Description: Converts incoming characters to uppercase, of course, there is no change to numbers, as can be seen in the following code example.

Specific use:

char a = 'a';
char b = '1';
char c = 'A';
System.out.println(Character.toUpperCase(a));
System.out.println(Character.toUpperCase(b));
System.out.println(Character.toUpperCase(c));
Copy the code

Running results:

A
1
A
Copy the code

Methods: toLowerCase

Description: Converts incoming characters to lowercase, similar to uppercase.

To use: Refer to the uppercase toUpperCase method for example code.

Operation result: same as above