In this example you are going to learn another example on using the java.lang.Character
class. The Character.isLowerCase()
method can be used to determine if a letter is a lowercase letter. This method takes a char
as argument and return a boolean value. If it returns true
it means the character is in lowercase form. And if it returns false
it means the character is not in lowercase form.
Beside using the isLowerCase()
method you can also compare the character type with the constant value of Character.LOWERCASE_LETTER
. To get the character type you can use the Character.getType()
method. You can see the example on the following code snippet.
package org.kodejava.lang;
public class CharacterIsLowerCaseExample {
public static void main(String[] args) {
char a = 'a';
// Checks to see if a letter is a lowercase letter.
if (Character.isLowerCase(a)) {
System.out.println(a + " is a lowercase letter.");
}
// Checks to see if a letter is a lowercase letter
// by comparing the character type against
// Character.LOWERCASE_LETTER constant value.
int charType = Character.getType(a);
if (charType == Character.LOWERCASE_LETTER) {
System.out.println(a + " is a lowercase letter.");
}
}
}
This example give you the following output:
a is a lowercase letter.
a is a lowercase letter.
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024