Web / Apache Commons Collections Interview questions
What are the types of Bag implementations in Commons Collections?
Commons Collections ships two core, non-decorator Bag implementations, plus several decorators that layer behavior on top of either one.
| HashBag | TreeBag |
| backed by a HashMap; no ordering guarantee | backed by a TreeMap; iterates in sorted order |
| elements need only equals()/hashCode() | elements must be Comparable or use a supplied Comparator |
On top of these, decorators like SynchronizedBag, UnmodifiableBag, and PredicatedBag wrap an existing Bag to add thread safety, immutability, or add-time validation respectively, without changing the underlying storage strategy.
More Related questions...