Multiset: a collection with order-independent equality that supports duplicates

A multiset (aka, a bag), is a similar to a set, but permits duplicate occurrences of elements. If you have ever used a Map<K, Integer> to keep track of element counts, check out Multiset<E> instead! It extends the Java Collection API with some convenient, new methods:
-Multiset#count(E) returns the total number of occurrences of an element, also called the frequency or multiplicity
-Multiset#entrySet returns a view of the multiset entries (which provides access to both the element and its count)
-Multiset#elementSet returns a set view of the elements (with duplicates collapsed)
-Bulk operations can be performed using Multiset#add(E, int), remove(E, int), or setCount(E, int)

Guava provides several different Multiset implementations:
-HashMultiset: backed by a HashMap; the most popular of the multiset implementations
-LinkedHashMultiset: backed by a LinkedHashMap; iteration order is defined by insertion order; 
-ImmutableMultiset: immutable; iteration order is defined by insertion order; does not permit null elements
-TreeMultiset: backed by a TreeMap; iteration order is defined by natural order or an explicit Comparator
-ImmutableSortedMultiset: backed by a sorted array; iteration order is defined by natural order or an explicit comparator; does not permit null elements;
-ConcurrentHashMultiset: supports concurrent modifications; does not permit null elements
-EnumMultiset: backed by an EnumMap; useful only with Enums

Have you ever used a Multiset before? If so, how has it improved your code?

Cheers,
-+Kurt Alfred Kluever, Guavian
Shared publiclyView activity