Java Convert ASCII String to UPPERCASE 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 uppercase String.

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 uppercase in Java

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

AsciiToUpperCaseExample1.java

import com.google.common.base.Ascii;

public class AsciiToUpperCaseExample1 {
    public static void main(String... args) {
        String inputString = "simple solution";

        String outputString = Ascii.toUpperCase(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 uppercase in Java

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

AsciiToUpperCaseExample2.java

import com.google.common.base.Ascii;

public class AsciiToUpperCaseExample2 {
    public static void main(String... args) {
        CharSequence inputString = "google guava tutorial";

        String outputString = Ascii.toUpperCase(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 uppercase in Java

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

AsciiToUpperCaseExample3.java

import com.google.common.base.Ascii;

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

        char outputChar = Ascii.toUpperCase(inputChar);

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

Output String: 
A

Happy Coding 😊