Quick revision
The short answer
I still use Commons Lang 3 for null-safe string work such as StringUtils.isBlank, abbreviate, substringBetween and defaultIfBlank, and for Validate and a few ObjectUtils methods. Many other helpers are better replaced by the JDK: String.join instead of StringUtils.join, streams and Arrays instead of most of ArrayUtils, records and Objects.hash instead of EqualsBuilder and HashCodeBuilder. The key difference is null handling: StringUtils.isBlank(null) returns true, while String.isBlank() needs an object and throws a NullPointerException on null.
What to remember
In this answer, we saw that the real difference between StringUtils.isBlank and String.isBlank is null: the Commons Lang method treats null as blank, and the JDK method throws. Commons Lang 3 still earns its place for null-safe helpers such as defaultIfBlank, abbreviate and substringBetween, and for Validate, while join, repeat, most ArrayUtils methods and the equals and hashCode builders are better replaced by the JDK. We also saw two version traps: the unmaintained commons-lang 2.x artifact, and Commons Text before 1.10.0 with CVE-2022-42889.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I still use Commons Lang 3 for null-safe string work such as StringUtils.isBlank, abbreviate, substringBetween and defaultIfBlank, and for Validate and a few ObjectUtils methods. Many other helpers are better replaced by the JDK: String.join instead of StringUtils.join, streams and Arrays instead of most of ArrayUtils, records and Objects.hash instead of EqualsBuilder and HashCodeBuilder. The key difference is null handling: StringUtils.isBlank(null) returns true, while String.isBlank() needs an object and throws a NullPointerException on null.
Why this question is asked
Commons Lang has been on the classpath of Java projects for twenty years, and many codebases call it out of habit for things the JDK has done well since Java 8 or 11. Interviewers ask this to see whether we know the JDK as it is today, and whether we understand the one property that still makes StringUtils useful: it treats null as a normal input. In this answer, we will compare isBlank in both forms, look at the Commons Lang helpers that still earn their place, see which ones the JDK replaced, and finish with two version traps: the old commons-lang 2.x artifact and Commons Text.
1A Quick Recap of Commons Lang 3
Apache Commons Lang is a library of small helpers for the classes in java.lang: String, Object, arrays, numbers and so on. Version 3 lives in the package org.apache.commons.lang3 and the Maven artifact org.apache.commons:commons-lang3. Its most used class is StringUtils, a collection of static methods for strings.
Its design rule is that almost every method accepts null and does something sensible with it instead of throwing. That rule made it popular in the Java 5 and 6 years, when the JDK's String class had very few helpers and code was full of null checks.
2StringUtils.isBlank Versus String.isBlank
Java 11 added String.isBlank(), which returns true if the string is empty or contains only white space. It is an instance method, so we can only call it on a real object.
Notice that the results agree for every non-null input. The only difference is null. So the choice depends on what null means in our code. If a value comes from a request parameter, an optional JSON field or a legacy database column, null is a normal input and StringUtils.isBlank says what we mean in one call. If our code has already guaranteed that the value is not null, for example a record component checked in its constructor, the JDK method is enough and saves a dependency.
There is a catch when we migrate: replacing StringUtils.isBlank(x) with x.isBlank() changes behaviour for null. A correct replacement is x == null || x.isBlank().
3Helpers That Still Earn Their Place
Several StringUtils methods have no short JDK equivalent and remain clearer than hand-written code. defaultIfBlank returns a fallback for null, empty or white space input. abbreviate shortens text for logs or UI and adds three dots. substringBetween extracts the text between two markers and returns null if either marker is missing, instead of throwing an index error.
Validate is useful at the edges of a system because it reads like a sentence and produces consistent IllegalArgumentException messages. ObjectUtils.firstNonNull is handy when choosing between several optional sources.
RandomStringUtils needs care. Its older static methods such as randomAlphanumeric were not clearly documented about which random source they used, so recent 3.x releases split it into secure() and insecure() instances and deprecated the old methods; check your version, as this arrived in the 3.15 to 3.17 range. For tokens, passwords or anything an attacker might guess, we always want the secure variant.
4Helpers the JDK Has Replaced
Many other Commons Lang helpers are now one JDK call. Using the JDK version removes a dependency and makes code easier for new team members, who learn the JDK first.
| Commons Lang 3 | JDK replacement | Since |
|---|---|---|
StringUtils.join(list, ",") | String.join(",", list) | Java 8 |
StringUtils.strip, isBlank | String.strip(), isBlank() (not null-safe) | Java 11 |
StringUtils.repeat("ab", 3) | "ab".repeat(3) | Java 11 |
ArrayUtils.contains(arr, x) | Arrays.asList(arr).contains(x) or a stream | Java 8 |
ArrayUtils.toPrimitive, reverse | streams, or keep ArrayUtils for primitives | Java 8 |
EqualsBuilder, HashCodeBuilder | records, Objects.equals, Objects.hash | Java 16, 7 |
ObjectUtils.defaultIfNull(a, b) | Objects.requireNonNullElse(a, b) | Java 9 |
StringEscapeUtils | Commons Text StringEscapeUtils | moved |
One difference is worth knowing. StringUtils.join treats null elements as empty strings, while String.join writes the word null. So String.join(",", List.of("a")) and StringUtils.join match, but with a list containing null the outputs differ: "a,null" against "a,". The same caution applies to every migration: the JDK methods are less forgiving about null, by design.
5Two Version Traps: commons-lang 2.x and Commons Text
The first trap is the old artifact. commons-lang:commons-lang, with the package org.apache.commons.lang, is version 2.x. Its last release, 2.6, came out in 2011 and it is no longer maintained. It still appears in old projects, often as a transitive dependency. We should use commons-lang3 everywhere and exclude the old artifact, because security scanners will flag it and nobody will fix it.
The second trap is Commons Text. Text features such as StringEscapeUtils and StringSubstitutor moved from Lang to the separate Commons Text library. In 2022, Commons Text had the vulnerability CVE-2022-42889, sometimes called Text4Shell. Its StringSubstitutor.createInterpolator() enabled lookups such as script:, dns: and url: by default, so if an application passed attacker-controlled text into it, the text could run code. Versions 1.5 to 1.9 were affected and 1.10.0 disabled those lookups by default. So whenever Commons Text is on the classpath, directly or through another library, we check that it is at least 1.10.0, and we never interpolate untrusted input.
6Follow-up questions
Should a new project add Commons Lang 3 at all?
Only if it will really use the null-safe helpers. Many Spring Boot projects already have it as a transitive dependency, so the cost is small. But if the only use would be join or isBlank on values that are never null, the JDK is enough and one dependency fewer is easier to maintain.
What is the difference between isBlank and isEmpty?
isEmpty is true only for a string of length zero, so " " is not empty. isBlank is true for empty strings and strings of only white space, so " " is blank. StringUtils has both, null-safe; the JDK has String.isEmpty since Java 6 and String.isBlank since Java 11.
Why did Commons Lang move escaping into Commons Text?
To keep Lang focused on small helpers for java.lang classes. Escaping, string similarity and substitution are text-processing features with more complex rules, so they got their own library. The StringEscapeUtils class in Lang 3 is deprecated, and new code should use the Commons Text version.
7Conclusion
In this answer, we saw that the real difference between StringUtils.isBlank and String.isBlank is null: the Commons Lang method treats null as blank, and the JDK method throws. Commons Lang 3 still earns its place for null-safe helpers such as defaultIfBlank, abbreviate and substringBetween, and for Validate, while join, repeat, most ArrayUtils methods and the equals and hashCode builders are better replaced by the JDK. We also saw two version traps: the unmaintained commons-lang 2.x artifact, and Commons Text before 1.10.0 with CVE-2022-42889.
Open with
The main thing Commons Lang 3 still gives me is null safety. StringUtils.isBlank(null) returns true, while String.isBlank from Java 11 is an instance method, so calling it on null throws a NullPointerException.
Then, if they want more
For every non-null input they agree. So when null is a normal input, like an optional request parameter, I still reach for StringUtils, and I also like defaultIfBlank, abbreviate, substringBetween and Validate, which read well and have no short JDK equivalent.
For RandomStringUtils, recent versions split it into secure and insecure variants, and I would use the secure one for anything sensitive.
On the other side, a lot of Commons Lang is replaced by the JDK now: String.join instead of StringUtils.join, repeat and strip on String, streams and Arrays instead of most of ArrayUtils, and records or Objects.hash instead of EqualsBuilder and HashCodeBuilder. When migrating I watch the null differences, for example String.join writes null where StringUtils.join writes nothing.
Two version points: I would never use the old commons-lang 2.x artifact, which has been unmaintained since 2011, and if Commons Text is on the classpath I make sure it is 1.10 or later because of the Text4Shell interpolation vulnerability.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 11, Java 5, Java 6, Java 8
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Which Apache Commons Lang 3 utilities do you still reach for, and which are better...": https://scrivio-interview-library.netlify.app/java/utility-libraries/f248e73e8f/