Web / Apache Commons Collections Interview questions
What is the difference between Apache Commons Collections 3.x and 4.x?
Commons Collections 4 was a deliberate, breaking redesign of the 3.x line rather than an incremental update, mainly to fix generics-related design problems that couldn't be solved without changing method signatures.
| Commons Collections 3.x | Commons Collections 4.x |
| org.apache.commons.collections | org.apache.commons.collections4 |
| largely raw-typed, pre-generics APIs requiring casts | fully generified, type-safe APIs |
| MultiMap extends Map, returning raw Object/Collection | MultiValuedMap is its own interface, properly typed |
| includes legacy classes like FastArrayList, ExtendedProperties | legacy/deprecated classes dropped |
Because the package name changed from org.apache.commons.collections to org.apache.commons.collections4, both versions can technically coexist on the same classpath without a naming collision - which is exactly what let projects migrate incrementally rather than needing an all-at-once cutover.
The generics rework is the change with the most day-to-day impact: code that used to need explicit casts after pulling values out of 3.x collections generally doesn't need them in 4.x, and mistakes that used to surface only as a runtime ClassCastException now get caught by the compiler instead.
More Related questions...