Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is StringUtils.isAllUpperCase in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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));
}
}
StringUtils.isAllUpperCase() in action

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.

RELATED TAGS

java
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring