Java Check Character is ASCII Alphabetic Upper Case using Apache Commons Lang

In this Java tutorial we learn how to check whether a character is an ASCII alphabetic upper case character using the CharUtils class of Apache Commons Lang library.

How to add Apache Commons Lang 3 library to your Java project

To use the Apache Commons Lang 3 library in the Gradle build project, add the following dependency into the build.gradle file.

implementation 'org.apache.commons:commons-lang3:3.12.0'

To use the Apache Commons Lang 3 library in the Maven build project, add the following dependency into the pom.xml file.

<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-lang3</artifactId>
  <version>3.12.0</version>
</dependency>

To have more information about the Apache Commons Lang 3 library you can visit the library home page at commons.apache.org/proper/commons-lang/

How to check a character is an ASCII alphabetic upper case

The Apache Commons Lang library provides the method CharUtils.isAsciiAlphaUpper() to check whether a given character is an ASCII alphabetic upper case or not. You can learn how to use the CharUtils.isAsciiAlphaUpper() method via the following code example.

CheckIsAsciiAlphaUpperChar.java

import org.apache.commons.lang3.CharUtils;

public class CheckIsAsciiAlphaUpperChar {
    public static void main(String... args) {
        boolean result1 = CharUtils.isAsciiAlphaUpper('a');
        boolean result2 = CharUtils.isAsciiAlphaUpper('A');
        boolean result3 = CharUtils.isAsciiAlphaUpper('7');
        boolean result4 = CharUtils.isAsciiAlphaUpper('-');
        boolean result5 = CharUtils.isAsciiAlphaUpper('\n');

        System.out.println("Character 'a' is ASCII alphabetic upper case result: " + result1);
        System.out.println("Character 'A' is ASCII alphabetic upper case result: " + result2);
        System.out.println("Character '7' is ASCII alphabetic upper case result: " + result3);
        System.out.println("Character '-' is ASCII alphabetic upper case result: " + result4);
        System.out.println("Character '\\n' is ASCII alphabetic upper case result: " + result5);
    }
}
The output is:
Character 'a' is ASCII alphabetic upper case result: false
Character 'A' is ASCII alphabetic upper case result: true
Character '7' is ASCII alphabetic upper case result: false
Character '-' is ASCII alphabetic upper case result: false
Character '\n' is ASCII alphabetic upper case result: false

Happy Coding 😊