The Apache Commons method StringUtils.isNotBlank will return false if the string is null, empty, or contains only whitespace. There will be differences in the following situations:

str1 str2 Results(1st code/2nd code)
null null false/true
"" "" false/true
" " " " false/true
Answer from k314159 on Stack Overflow
🌐
Spring
docs.spring.io › spring-framework › docs › current › javadoc-api › org › springframework › util › StringUtils.html
StringUtils (Spring Framework 7.0.6 API)
The Object signature is useful for general attribute handling code that commonly deals with Strings but generally has to iterate over Objects since attributes may, for example, be primitive value objects as well. Note: If the object is typed to String upfront, prefer hasLength(String) or hasText(String) instead. ... Check that the given CharSequence is neither null nor of length 0. Note: this method returns true for a CharSequence that purely consists of whitespace. StringUtils.hasLength(null) = false StringUtils.hasLength("") = false StringUtils.hasLength(" ") = true StringUtils.hasLength("Hello") = true
🌐
GitHub
github.com › openrewrite › rewrite-spring › issues › 475
`StringUtils#isEmpty` is not equivalent to `ObjectUtils#isEmpty` for collections · Issue #475 · openrewrite/rewrite-spring
January 12, 2024 - But the stricter check in ObjectUtils now checks if its any collection and the collection is empty or not. Its an idiosyncracy from our codebase, but the expectation from rewrite plugin was the code changes would be one-to-one, just a null check ...
Author   timtebeek
🌐
GitHub
github.com › spring-projects › spring-framework › issues › 25945
Deprecate `StringUtils.isEmpty(Object)` and replace remaining usage (e.g. with `ObjectUtils.isEmpty`) · Issue #25945 · spring-projects/spring-framework
October 21, 2020 - With static imports code like this looks perfectly fine: List data = ... if (isEmpty(data)) { But if the import has StringUtils.isEmpty the condition above will not work correctly for empty List introducing a hidden, difficult to...
Author   sabi0
🌐
Medium
medium.com › @vallalashraven › understanding-stringutils-hastext-stringutils-and-objectutils-in-spring-a-practical-guide-1a24b70d70f4
Understanding StringUtils.hasText(), StringUtils, and ObjectUtils in Spring: A Practical Guide | by Vallala Sravan kumar | Medium
November 24, 2025 - ObjectUtils.isEmpty(null); // true ObjectUtils.isEmpty(""); // true ObjectUtils.isEmpty(new int[]{}); // true ObjectUtils.isEmpty(List.of()); // true ObjectUtils.isEmpty(" "); // false · Note that " " (a whitespace string) is not considered empty. For validating fields where whitespace-only values are invalid. if (!StringUtils.hasText(username)) { throw new IllegalArgumentException("Username cannot be empty"); }
🌐
Medium
medium.com › @vino7tech › useful-stringutils-methods-in-java-833dc5236f0a
Useful StringUtils Methods in Java | by Vinotech | Medium
September 29, 2024 - StringUtils is a utility class commonly used in Java to perform operations on String objects. It contains a collection of static methods…
🌐
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › org › apache › commons › lang3 › ObjectUtils.html
ObjectUtils (Apache Commons Lang 3.21.0-SNAPSHOT API)
Use this method for validation, for example: public Foo(Bar bar) { this.bar = Objects.requireNonEmpty(bar, "bar"); } ... T - the type of the reference. ... NullPointerException - if obj is null. IllegalArgumentException - if obj is empty per isEmpty(Object). ... Gets the toString() of an Object ...
Find elsewhere
🌐
Spring
docs.spring.io › spring-framework › docs › current › javadoc-api › org › springframework › util › ObjectUtils.html
ObjectUtils (Spring Framework 7.0.6 API)
public abstract class ObjectUtils extends Object · Miscellaneous object utility methods. Mainly for internal use within the framework. Thanks to Alex Ruiz for contributing several enhancements to this class! Since: 19.03.2004 · Author: Juergen Hoeller, Keith Donald, Rod Johnson, Rob Harrop, Chris Beams, Sam Brannen · See Also: ClassUtils · CollectionUtils · StringUtils ·
🌐
Medium
khmarbaise.medium.com › java-does-not-offer-stringutils-objectutils-or-collectionutils-a-supplemental-library-4f458b1be477
Java does NOT offer StringUtils, ObjectUtils or CollectionUtils (a supplemental library…
April 8, 2024 - Java offers smarter, more readable alternatives that scale with your project. By using utility classes like StringUtils, ObjectUtils, and CollectionUtils, or embracing Optional, you'll write cleaner code, dodge null pointer exceptions, and make your futur…
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.9 › org › apache › commons › lang3 › ObjectUtils.html
ObjectUtils (Apache Commons Lang 3.9 API)
ObjectUtils.isNotEmpty(null) = false ObjectUtils.isNotEmpty("") = false ObjectUtils.isNotEmpty("ab") = true ObjectUtils.isNotEmpty(new int[]{}) = false ObjectUtils.isNotEmpty(new int[]{1,2,3}) = true ObjectUtils.isNotEmpty(1234) = true
🌐
Medium
tamerardal.medium.com › simplify-null-checks-in-java-writing-clean-code-with-apache-commons-lang-3-e7d3aea207bd
Simplify Null Checks in Java: Writing Clean Code with Apache Commons Lang 3 | by Tamer Ardal | Medium
September 18, 2024 - Integer age = ObjectUtils.defaultIfNull(inputAge, 18); Especially when working with String values, we need to do a lot of null or empty checking. In this case, we can easily do this with the StringUtils class.
🌐
GitHub
github.com › apache › commons-lang › blob › master › src › main › java › org › apache › commons › lang3 › ObjectUtils.java
commons-lang/src/main/java/org/apache/commons/lang3/ObjectUtils.java at master · apache/commons-lang
* ObjectUtils.toString(Boolean.TRUE) = "true" * </pre> * * @param obj the Object to {@code toString()}, may be {@code null}. * @return the input's {@code toString()}, or {@code ""} if the input is {@code null}. * @see Objects#toString(Object) * @see Objects#toString(Object, String) * @see StringUtils#defaultString(String) * @see String#valueOf(Object) * @since 2.0 ·
Author   apache
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-handling-with-apache-commons-stringutils-class-in-java
String Handling with Apache Commons' StringUtils Class in Java - GeeksforGeeks
April 28, 2025 - import org.apache.commons.lang3.StringUtils; public class StringUtilsExample { public static void main(String[] args) { String str = " hello world "; // isEmpty() example boolean empty = StringUtils.isEmpty(str); System.out.println("Is the string empty? " + empty); // isBlank() example boolean blank = StringUtils.isBlank(str); System.out.println("Is the string blank?
🌐
Baeldung
baeldung.com › home › java › java string › checking for empty or blank strings in java
Checking for Empty or Blank Strings in Java | Baeldung
January 8, 2024 - Furthermore, the Spring Core library provided a class named StringUtils which has a method to check if a string is empty. However, the class was deprecated in the Spring 5.3.0 version and above. It’s replaced with the ObjectUtils class.
🌐
OpenRewrite
docs.openrewrite.org › recipe catalog › java › spring › spring framework › use `objectutils#isempty(object)`
Use ObjectUtils#isEmpty(Object) | OpenRewrite Docs
recipeList: - org.openrewrite.java.ChangeMethodTargetToStatic: methodPattern: org.springframework.util.StringUtils isEmpty(Object) fullyQualifiedTargetTypeName: org.springframework.util.ObjectUtils
Published   April 8, 2025