Some Built In Character Methods
The Character Class. Another class you are likely to want to gain some competence with has to do with Characters and their manipulation. The following table contains several methods in the Character class. Since these are likely less familiar to you we will present a small program. |
class Character in (java.lang package) | |
Method |
Description |
Character.isDigit(ch) | Returns whether
something is a numerical digit ch is a character, returns a boolean |
Character.isLetter(ch) | Returns whether
something is a letter ch is a character, returns a boolean |
Character.isLowerCase(ch) | Returns whether
something is lower case ch is a character, returns a boolean |
Character.isUpperCase(ch) | Returns whether
something is upper case ch is a character, returns a boolean |
Character.isSpaceChar(ch) | Returns whether
or not the character is a blank space ch is a character, returns a boolean |
Character.isWhitespace(ch) | Returns whether
or not the character is a blank space or control character such as \n, \t
or \r ch is a character, returns a boolean |
Character.toLowerCase(ch) | Converts the
character to lower case Returns a char |
Character.toUpperCase(ch) | Converts the
character to upper case Returns a char |
Now you want to run the following program called CharacterSampler.java. This will just do some manipulations on a string that I have written into the program in order to illustrate some useful issues. It also uses some of these methods on strings that are defined within the code. |
import javax.swing.*; public class CharacterSampler {
} |
What the code does is
This is demonstrated in the following display of the results of the program. |