Java Convert ASCII String to lowercase using Google Guava

Tags: Google Guava Ascii String CharSequence char Convert

In this Java tutorial we learn how to use the com.google.common.base.Ascii class of Google Guava library to convert ASCII String or character to lowercase.

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 Convert ASCII String to lowercase in Java

In the following Java example program we learn how to use the Ascii.toLowerCase() method to convert a ASCII String to lowercase.

AsciiToLowerCaseExample1.java

import com.google.common.base.Ascii;

public class AsciiToLowerCaseExample1 {
    public static void main(String... args) {
        String inputString = "SIMPLE Solution";

        String outputString = Ascii.toLowerCase(inputString);

        System.out.println("Input String: \n" + inputString);
        System.out.println("\nOutput String: \n" + outputString);
    }
}
The output is:
Input String: 
SIMPLE Solution

Output String: 
simple solution

How to Convert ASCII CharSequence to lowercase in Java

In the following Java example program we learn how to use the Ascii.toLowerCase() method to convert a ASCII CharSequence to lowercase.

AsciiToLowerCaseExample2.java

import com.google.common.base.Ascii;

public class AsciiToLowerCaseExample2 {
    public static void main(String... args) {
        CharSequence inputString = "GOOGLE GUAVA Tutorial";

        String outputString = Ascii.toLowerCase(inputString);

        System.out.println("Input CharSequence: \n" + inputString);
        System.out.println("\nOutput String: \n" + outputString);
    }
}
The output is:
Input CharSequence: 
GOOGLE GUAVA Tutorial

Output String: 
google guava tutorial

How to Convert ASCII char to lowercase in Java

In the following Java example program we learn how to use the Ascii.toLowerCase() method to convert a ASCII char to lowercase.

AsciiToLowerCaseExample3.java

import com.google.common.base.Ascii;

public class AsciiToLowerCaseExample3 {
    public static void main(String... args) {
        char inputChar = 'S';

        char outputChar = Ascii.toLowerCase(inputChar);

        System.out.println("Input String: \n" + inputChar);
        System.out.println("\nOutput String: \n" + outputChar);
    }
}
The output is:
Input String: 
S

Output String: 
s

Happy Coding 😊