Quick revision
The short answer
My policy is JDK collections by default, because the additions of Java 9 to 21 cover immutable factories and sequenced access, which were the main reasons teams reached for Guava. Specialised libraries such as a primitive collections library are allowed where measured memory or CPU gains justify them, third-party collection types never appear in shared APIs, the approved set is kept small so upgrades stay manageable, and a short guide with examples explains how to choose.
What to remember
In this answer, we set a policy for collection libraries: JDK collections by default, since they now cover immutable factories and sequenced access; specialised libraries such as one primitive collections library where measured gains justify them; no third-party collection types in shared APIs; a small approved set enforced in the build; and a short guide with examples, reviewed as the JDK evolves.
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.
My policy is JDK collections by default, because the additions of Java 9 to 21 cover immutable factories and sequenced access, which were the main reasons teams reached for Guava. Specialised libraries such as a primitive collections library are allowed where measured memory or CPU gains justify them, third-party collection types never appear in shared APIs, the approved set is kept small so upgrades stay manageable, and a short guide with examples explains how to choose.
Background to this question
Collection libraries look harmless: one dependency, a few nicer types. Across a company with hundreds of services, though, four overlapping libraries mean four upgrade cycles, version conflicts between transitive dependencies, and shared APIs that force consumers to adopt a library they did not choose. A senior engineer is expected to set a policy that keeps the real benefits and removes the friction. In this answer, we will look at why teams add these libraries, what the JDK now covers, where specialised libraries still earn their place, why API boundaries matter most, and how to write and maintain the policy.
1Why Teams Add These Libraries
Each of the four libraries in the question solved a real problem when it was adopted. Guava brought immutable collections, multimaps, multisets and many utilities at a time when the JDK had only unmodifiable views. fastutil and Eclipse Collections bring primitive collections, maps and lists of int and long that avoid boxing and can cut memory several times over. Eclipse Collections also offers a rich API on its object collections. Vavr brings persistent, immutable collections in the style of functional languages, along with types such as Option and Either.
So the starting point is respect for the reasons. A policy that simply bans libraries will be ignored, or will push teams to write worse versions themselves. The aim is to keep the cases where a library clearly pays off and remove the ones where the JDK is now good enough.
2What the JDK Covers Now
Much of Guava's original value has moved into the JDK. Java 9 added List.of, Set.of and Map.of, which give compact unmodifiable collections. Java 10 added List.copyOf and the toUnmodifiable collectors. Java 16 added Stream.toList. Java 21's sequenced collections give getFirst, getLast and reversed views on ordered collections. Streams cover most of the transformation utilities, and Map.computeIfAbsent with a List value covers the simple multimap case.
That is why the default is the JDK. Code that uses only JDK collections needs no extra dependency, every Java developer can read it, and it upgrades with the JDK. The guide should say this plainly and show the JDK version of the common Guava idioms, so teams see that they lose little.
3Where Specialised Libraries Earn Their Place
Primitive collections are the clearest case. A HashMap<Long, Integer> with 50 million entries uses about 4 GB, while a primitive long-to-int map holds the same data in about 800 MB. No JDK collection does this. So the policy allows one primitive collections library for high-volume data, with a simple condition: the team shows a measurement, such as a heap histogram or a benchmark, that justifies it. A map of ten thousand entries does not need one.
Guava stays allowed for things the JDK still lacks, such as its graph types, range sets, or rich multimaps where they make code much clearer. For caching, Caffeine has taken over from Guava's cache. Vavr is the hardest case. Its persistent collections are useful in a few algorithm-heavy modules, but its types spread quickly through signatures, and its value as an Either library is smaller now that sealed interfaces and records exist. I would allow it only inside a module, with a reason.
| Library | Status | Condition |
|---|---|---|
| JDK collections | Default | Use for everything unless a case below applies |
| One primitive library (e.g. fastutil) | Approved | Measured memory or CPU gain on large data |
| Guava | Approved, limited | Features the JDK lacks; not for immutables or reverse |
| Eclipse Collections | Case by case | Only if chosen as the single primitive library |
| Vavr | Exception only | Inside one module, with a written reason |
4The Most Important Rule: Keep Them Out of Shared APIs
Whatever is used inside a service, shared APIs must expose only JDK types. When a library publishes a method that returns Guava's ImmutableList or Vavr's List, every consumer must depend on that library, at a compatible version, and learn its types. If two shared libraries expose different versions of Guava, their consumers can end up with version conflicts that are painful to resolve.
So the rule is that public methods of shared libraries, client SDKs and event payloads take and return java.util types: List, Set, Map, or plain arrays for primitive data. A primitive map can stay inside the implementation, with a method such as int countFor(long id) on the outside. This one rule removes most of the long-term cost of third-party collections, because it keeps the choice local to the team that made it.
5Writing and Maintaining the Policy
I would keep the approved set short, one library per need, so that a dependency upgrade is a small number of known projects rather than a hunt across the company. The build can enforce it: a dependency rule in the build tool or a check in the shared parent build flags libraries outside the list, and an ArchUnit test in shared libraries stops non-JDK collection types from appearing in public signatures.
The guide itself should be short, a page or two, with examples: the JDK equivalents of common idioms, a worked case of when a primitive map is justified, and the API rule with a before and after. I would review it once a year, because the JDK keeps moving, and every new JDK release may remove another reason to depend on a library. Teams that want an exception ask in a short written proposal, which also gives us the data to update the policy.
6Follow-up questions
What do you do about existing code that already uses Vavr everywhere?
I would not force a rewrite. The rule applies to new code and to public APIs first. Internal use can stay, and when a module is reworked, its team can move to JDK types and sealed records. Over time the dependency shrinks to the places where it still adds value.
Is Guava itself a problem?
Guava is high quality, but it is a large dependency that many other libraries also pull in at different versions, and it has removed APIs in the past. That makes it a common source of version conflicts. Keeping it out of public APIs and using it only for features the JDK lacks keeps that risk small.
How do you check a team's measurement for a primitive library?
I would ask for a before-and-after heap histogram or a JMH benchmark on realistic data, along with the change in instance memory or latency. If the gain is a few megabytes, the extra dependency is not worth it.
7Conclusion
In this answer, we set a policy for collection libraries: JDK collections by default, since they now cover immutable factories and sequenced access; specialised libraries such as one primitive collections library where measured gains justify them; no third-party collection types in shared APIs; a small approved set enforced in the build; and a short guide with examples, reviewed as the JDK evolves.
Open with
My default is JDK collections. Since Java 9 we have List.of and Map.of, since 10 copyOf, since 16 Stream.toList, and since 21 sequenced collections with getFirst and reversed, so the main reasons teams used Guava are covered, and JDK code needs no dependency and upgrades with the platform.
Then, if they want more
I do allow specialised libraries where they bring something the JDK cannot, mainly primitive collections. A map of 50 million longs to ints is about 4 GB as a HashMap and under 1 GB as a primitive map, so with a measurement, that is clearly justified.
I would approve one primitive library for the company, not several, and keep Guava for features the JDK lacks. Vavr I would only allow inside a module with a reason, because its types spread and sealed records now cover its Either case.
The rule I care most about is that third-party collection types never appear in shared APIs, like client libraries or event payloads. Otherwise every consumer has to depend on that library and its version, and we get conflicts across the company. Internally a team can use a primitive map behind a method with plain types.
I would keep the approved set small and enforce it in the shared build and with an ArchUnit check on public signatures. Finally, I would write a short guide with JDK equivalents of common idioms and review it each year.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 9, Java 10, Java 16
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Collections Framework, overview, java.util, package documentation
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 "Teams in your company often add third-party collection libraries such as Guava...": https://scrivio-interview-library.netlify.app/java/collections-overview/6b80838907/