What is StringUtils.isAllEmpty() in Java?

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

Free Resources

Attributions:
  1. undefined by undefined