Java Check ASCII Character is lowercase using Google Guava

Tags: Google Guava Ascii char

In this Java tutorial we learn how to use the com.google.common.base.Ascii class of Google Guava library to indicate whether an ASCII character is a lowercase character.

How to add Google Guava library to the Java project

To use the Google Guava library in the Gradle build project, add the following dependency into the build.gradle file.

implementation group: 'com.google.guava', name: 'guava', version: '30.1.1-jre'

To use the Google Guava library in the Maven build project, add the following dependency into the pom.xml file.

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>30.1.1-jre</version>
</dependency>

To have more information about the Google Guava library you can visit the project home page at guava.dev

How to check a char value is lowercase in Java

To check whether a char value is lowercase or not in Java we can use the Ascii.isLowerCase() method of Google Guava library. We show you how to use the Ascii.isLowerCase() method in the following Java example program.

AsciiIsLowerCaseExample.java

import com.google.common.base.Ascii;

public class AsciiIsLowerCaseExample {
    public static void main(String... args) {
        boolean result1 = Ascii.isLowerCase('a');
        boolean result2 = Ascii.isLowerCase('A');
        boolean result3 = Ascii.isLowerCase('1');
        boolean result4 = Ascii.isLowerCase('@');

        System.out.println("'a' is lowercase: " + result1);
        System.out.println("'A' is lowercase: " + result2);
        System.out.println("'1' is lowercase: " + result3);
        System.out.println("'@' is lowercase: " + result4);
    }
}
The output is:
'a' is lowercase: true
'A' is lowercase: false
'1' is lowercase: false
'@' is lowercase: false

Happy Coding 😊