How do I know if a character is uppercase?

In the previous example How do I know if a character is lowercase?, we’ve learned how to use the Character.isLowerCase() method. Now we will learn how to use the other method, which is the Character.isUpperCase() to determine if a letter is in an uppercase form. This method also return a boolean value that indicates whether the character is in uppercase form or not.

But first things first. Before you dive into the learning, make sure all other matters are taken care of, as learning to code will require your absolute dedication. If you are a student, you can use essay writing services to outsource some of your assignments. If you work full-time, consider taking a few days off. This way, you will get a clearer mind and more energy for studying.

Another way to check if a letter is in uppercase form is by comparing the type of the characters, that can be obtained using the Character.getType() method with a defined constant value Character.UPPERCASE_LETTER.

Below is the code snippet that demonstrate these methods.

package org.kodejava.example.lang;

public class CharacterIsUpperCaseExample {
    public static void main(String[] args) {
        char a = 'A';

        // Checks to see if a letter is a uppercase letter.
        if (Character.isUpperCase(a)) {
            System.out.println(a + " is an uppercase character.");
        }

        // Checks to see if a letter is an uppercase letter
        // by comparing the character type against
        // Character.UPPERCASE_LETTER constant value.
        int charType = Character.getType(a);
        if (charType == Character.UPPERCASE_LETTER) {
            System.out.println(a + " is an uppercase character.");
        }
    }
}

The above example give you the following result when it executed:

A is an uppercase character.
A is an uppercase character.
Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.