What is StringUtils.isAllUpperCase in Java?

isAllUpperCase is a static method of the StringUtils class that checks whether all the characters in a given string are uppercase or not.

You can use Character.isUpperCase to determine if a character is uppercase or not.

How to import StringUtils

StringUtils is defined in the Apache Commons Lang package. Apache Commons Lang can be added to the Maven project by adding the following dependency to the pom.xml file.

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

Note: For other versions of the commons-lang package, refer to the Maven Repository.

You can import the StringUtils class as follows:

import org.apache.commons.lang3.StringUtils;

Syntax


public static boolean isAllUpperCase(final CharSequence cs)

Parameters

  • CharSequence cs: The character sequence to check.

Return value

The function returns true if all the characters in the character sequence are uppercase. Otherwise, it returns false.

Code

import org.apache.commons.lang3.StringUtils;
public class Main{
public static void main(String[] args){
String characterSequence = "EDUCATIVE";
System.out.println(StringUtils.isAllUpperCase(characterSequence));
characterSequence = "EdUCATIVE";
System.out.println(StringUtils.isAllUpperCase(characterSequence));
}
}

Output

The output of the code will be as follows:


true
false

Explanation

  1. string = "EDUCATIVE".

The function returns true since all the characters in the string are uppercase.

  1. string = "EdUCATIVE".

The function returns false since the character d is lowercase.