Java Character Class Methods
Simple programs demonstrating 8 key methods of the Character class
Note: All methods shown below are static methods of the [Link] class. No import statement
is required — they are available by default in Java.
1. isLetter()
Determines whether the specified char value is a letter (a–z or A–Z). Returns true if it is a letter, false
otherwise.
public class IsLetterDemo {
public static void main(String[] args) {
char c1 = 'A';
char c2 = '5';
[Link]([Link](c1)); // true
[Link]([Link](c2)); // false
}
}
2. isDigit()
Determines whether the specified char value is a digit (0–9). Returns true if it is a digit, false
otherwise.
public class IsDigitDemo {
public static void main(String[] args) {
char c1 = '9';
char c2 = 'B';
[Link]([Link](c1)); // true
[Link]([Link](c2)); // false
}
}
3. isWhitespace()
Determines whether the specified char value is white space (space, tab, newline, etc.). Returns true if
it is whitespace.
public class IsWhitespaceDemo {
public static void main(String[] args) {
char c1 = ' ';
char c2 = 'Z';
[Link]([Link](c1)); // true
[Link]([Link](c2)); // false
}
}
4. isUpperCase()
Determines whether the specified char value is an uppercase letter. Returns true only if the character
is uppercase.
public class IsUpperCaseDemo {
public static void main(String[] args) {
char c1 = 'G';
char c2 = 'g';
[Link]([Link](c1)); // true
[Link]([Link](c2)); // false
}
}
5. isLowerCase()
Determines whether the specified char value is a lowercase letter. Returns true only if the character is
lowercase.
public class IsLowerCaseDemo {
public static void main(String[] args) {
char c1 = 'm';
char c2 = 'M';
[Link]([Link](c1)); // true
[Link]([Link](c2)); // false
}
}
6. toUpperCase()
Returns the uppercase form of the specified char value. If the character is already uppercase or not a
letter, it is returned unchanged.
public class ToUpperCaseDemo {
public static void main(String[] args) {
char c = 'j';
char upper = [Link](c);
[Link](upper); // J
}
}
7. toLowerCase()
Returns the lowercase form of the specified char value. If the character is already lowercase or not a
letter, it is returned unchanged.
public class ToLowerCaseDemo {
public static void main(String[] args) {
char c = 'K';
char lower = [Link](c);
[Link](lower); // k
}
}
8. toString()
Returns a String object representing the specified character value — essentially a one-character
string. Useful when String methods are needed on a char.
public class ToStringDemo {
public static void main(String[] args) {
char c = 'P';
String s = [Link](c);
[Link](s); // P
[Link]([Link]()); // 1
}
}
Java Character Class Methods — Simple Programs Reference