上QQ阅读APP看书,第一时间看更新
Commons Collections
The Java Collections API is very powerful and it defines a good set of abstractions for data structures in Java. The Commons Collections use these abstractions and extend the standard Collections API with new implementations as well as new collections. To include the library, use this snippet:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
Some useful collections from this library are:
- Bag: This is an interface for sets that can hold the same element multiple times
- BidiMap: This stands for Bi-directional map. It can map from keys to values and from values to keys
It has some overlap with collections from Google Guava, explained in the next session, but has some additional collections that aren't implemented there. For example,
- LRUMap: This is used for implementing caches
- PatriciaTrie: This is used for fast string prefix lookups