On this page
Apache Commons
Prev: third_party/java | Up: third_party/java | Next: Google Guava
Rel: java.util, java.nio & java.io, String, Google Guava
Ref: Apache Commons Official Site | Maven Central
Tags: #public #prog #java #third-party #utilities #tier/standard
Overview
Apache Commons is a family of small, focused, zero-or-minimal-dependency Java utility libraries. Rather than a single monolith, you add only the specific component you need (e.g., commons-lang3, commons-io, commons-csv).
Most Widely Used Components
Artifact (org.apache.commons) |
Purpose | Key Classes |
|---|---|---|
commons-lang3 |
Null-safe String, Array, Number, Object, and reflection helpers |
StringUtils, ArrayUtils, Validate, Pair / Triple, StopWatch |
commons-io |
High-level stream, file, filename, and directory utilities | FileUtils, IOUtils, FilenameUtils, TeeOutputStream |
commons-collections4 |
Specialized collections & null-safe helpers | CollectionUtils, BidiMap, Bag, LRUMap |
commons-csv |
RFC 4180 / Excel / TSV CSV parsing & formatting | CSVFormat, CSVParser, CSVPrinter |
commons-text |
Advanced string similarity, escaping, and substitution | StringSubstitutor, StringEscapeUtils, LevenshteinDistance |
Common Patterns (commons-lang3 & commons-io)
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.io.FilenameUtils;
// Null-safe string checks and normalization (never throws NullPointerException)
String slug = StringUtils.defaultIfBlank(rawInput, "untitled").trim();
boolean hasDigits = StringUtils.isNumeric("4200");
String truncated = StringUtils.abbreviate(longTitle, 40);
// Cross-platform path & extension parsing
String ext = FilenameUtils.getExtension("/var/log/app.tar.gz"); // "gz"
String base = FilenameUtils.getBaseName("/var/log/report.csv"); // "report"
When Modern JDK Replaces Apache Commons
Java 11–21 absorbed several classic Commons helpers—prefer the standard library when it is already concise:
StringUtils.isBlank(s)vs.s == null || s.isBlank()(useStringUtilsonly if null-safety across many call sites is a win).FileUtils.readFileToString(...)→ preferFiles.readString(path, StandardCharsets.UTF_8)(Java 11+).IOUtils.copy(in, out)→ preferin.transferTo(out)(Java 9+).Validate.notNull(x)→ preferObjects.requireNonNull(x, "msg").- Legacy
commons-lang(v2, packageorg.apache.commons.lang) is#tier/legacy— always usecommons-lang3(org.apache.commons.lang3).
Linked from
Related notes
- tuts/third_party/java/guava Linked here; links to this page; shared tags: #java, #prog, #tier, #utilities
- tuts/third_party/java Linked here; links to this page; shared tags: #java, #prog
- tuts/java/builtins/String Linked here; shared tags: #java, #prog, #tier
- tuts/java links to this page; shared tags: #java, #prog
- tuts/java/stdlib/java_nio_and_io Linked here; shared tags: #java, #prog
- tuts/java/stdlib/java_util Linked here; shared tags: #java, #prog
- tuts/interop/java_and_c_ffm_and_jni shared tags: #java, #prog, #tier
- tuts/java/builtins/AutoCloseable shared tags: #java, #prog, #tier
- tuts/java/builtins/enum shared tags: #java, #prog, #tier
- tuts/java/builtins/final shared tags: #java, #prog, #tier