Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
stringutils
communitycreator

What is StringUtils.isAllEmpty() 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.

isAllEmpty is a static method of the StringUtils() class that checks whether all the strings in the given list are empty or null.

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 isAllEmpty(final CharSequence... css)

Parameters

The function takes in two parameters:

  • CharSequence... css: Character sequences to check.

Return value

The function returns true if all the character sequences are neither empty nor null. Otherwise, it returns false.

Code

import org.apache.commons.lang3.StringUtils;

public class Main{

    public static void main(String[] args){
        System.out.println(StringUtils.isAllEmpty("educative", "", "  educative  "));
        System.out.println(StringUtils.isAllEmpty( "", null));
    }
}

Explanation

  1. character sequences = ["educative", "", " educative "].

The function returns false since some of the strings are neither empty nor null.

  1. string = ["", null].

The function returns true since all the strings in the string list are either empty or null.

Output

The output of the code will be as follows:


false
true

RELATED TAGS

java
stringutils
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