Understanding Apache Commons StringUtils: isEmpty, isBlank, and Related Methods
This article explains the differences and usage of Apache Commons Lang3 StringUtils methods such as isEmpty, isNotEmpty, isAnyEmpty, isNoneEmpty, isBlank, isNotBlank, isAnyBlank, and isNoneBlank, providing code examples and behavioral details for handling null, empty, and whitespace strings in Java.
A new colleague with three years of Java experience still confuses the differences between isEmpty and isBlank , using them indiscriminately. The article invites readers to explore the comprehensive utility class org.apache.commons.lang3.StringUtils together.
isEmpty series
StringUtils.isEmpty()
Determines whether a CharSequence is null or has a length of zero; a single space character is not considered empty.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = falseStringUtils.isNotEmpty()
Returns the logical negation of isEmpty() .
public static boolean isNotEmpty(final CharSequence cs) {
return !isEmpty(cs);
}StringUtils.isAnyEmpty()
Evaluates to true if any of the supplied CharSequence arguments is null or empty.
StringUtils.isAnyEmpty(null) = true
StringUtils.isAnyEmpty(null, "foo") = true
StringUtils.isAnyEmpty("", "bar") = true
StringUtils.isAnyEmpty("bob", "") = true
StringUtils.isAnyEmpty(" bob ", null) = true
StringUtils.isAnyEmpty(" ", "bar") = false
StringUtils.isAnyEmpty("foo", "bar") = falseStringUtils.isNoneEmpty()
Returns true only when all supplied arguments are non‑null and non‑empty, i.e., the opposite of isAnyEmpty() .
public static boolean isNoneEmpty(final CharSequence... css) {
return !isAnyEmpty(css);
}isBlank series
StringUtils.isBlank()
Checks whether a CharSequence is null , empty, or consists solely of whitespace characters.
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = falseStringUtils.isNotBlank()
Logical negation of isBlank() .
public static boolean isNotBlank(final CharSequence cs) {
return !isBlank(cs);
}StringUtils.isAnyBlank()
Returns true if any argument is null , empty, or whitespace only.
StringUtils.isAnyBlank(null) = true
StringUtils.isAnyBlank(null, "foo") = true
StringUtils.isAnyBlank(null, null) = true
StringUtils.isAnyBlank("", "bar") = true
StringUtils.isAnyBlank("bob", "") = true
StringUtils.isAnyBlank(" bob ", null) = true
StringUtils.isAnyBlank(" ", "bar") = true
StringUtils.isAnyBlank("foo", "bar") = falseStringUtils.isNoneBlank()
Evaluates to true only when none of the arguments are null , empty, or whitespace only.
public static boolean isNoneBlank(final CharSequence... css) {
return !isAnyBlank(css);
}Other StringUtils methods
For a complete list of utilities, refer to the official Apache Commons Lang documentation:
https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.