Multiset
A generic unordered collection that supports order-independent equality, like Set, but may have duplicate elements. A multiset is also sometimes called a bag.
Methods in this interface support only read-only access to the set; read/write access is supported through the MutableMultiset interface.
See the Guava User Guide article on Multiset.
See also
Parameters
the type of elements contained in the set. The set is covariant in its element type.
Functions
Returns the number of occurrences of an element in this multiset (the count of the element). Note that for an Object.equals-based multiset, this gives the same result as Collections.frequency (which would presumably perform more poorly).
Properties
Returns a read-only Collection of all elements in this set, grouped into Multiset.Entry instances, each providing an element of the multiset and the count of that element.
Inheritors
Extensions
Returns a string representation of this, with the format [e1, e2, ..., en] (that is, identical to Arrays.toString(Iterables.toArray(iterable))). Note that for most implementations of Collection, collection.toString() also gives the same result, but that behavior is not generally guaranteed.
Combines two iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in other. The source iterators are not polled until necessary.
Combines three iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in a, followed by the elements in b. The source iterators are not polled until necessary.
Combines four iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in a, followed by the elements in b, followed by the elements in c. The source iterators are not polled until necessary.
Combines multiple iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements of each iterable in iterables sequentially. The source iterators are not polled until necessary.
Returns the elements of this that satisfy a predicate. The returned collection is a live view of this; changes to one affect the other.
Returns a view of this containing all elements that satisfy the input predicate retainIfTrue.
Combines multiple iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this sequentially. The source iterators are not polled until necessary.
Combines two iterators into a single iterator. The returned iterator iterates across the elements in this sequentially. The source iterators are not polled until necessary.
Returns an iterable over the merged contents of all given Iterables in this. Equivalent entries will not be de-duplicated.
Returns an iterator over the merged contents of all given this, traversing every element of the input iterators. Equivalent entries will not be de-duplicated.
Returns an unmodifiable view of the difference of two multisets. In the returned multiset, the count of each element is the result of the zero-truncated subtraction of its count in the second multiset from its count in the first multiset, with elements that would have a count of 0 not included. The iteration order of the returned multiset matches that of the element set of this, with repeated occurrences of the same element appearing consecutively.
Returns a Collection of all the permutations of the specified Iterable using naturalOrder for establishing the lexicographical ordering.
Returns a Collection of all the permutations of the specified Iterable using the specified selector for establishing the lexicographical ordering.
Returns a Collection of all the permutations of the specified Iterable using the specified comparator for establishing the lexicographical ordering.
Divides an iterable into unmodifiable sublists of the given size, padding the final iterable with null values if necessary. For example, partitioning an iterable containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e, null]] -- an outer iterable containing two inner lists of three elements each, all in the original order.
Divides an iterable into unmodifiable sublists of the given size (the final iterable may be smaller). For example, partitioning an iterable containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer iterable containing two inner lists of three and two elements, all in the original order.
Returns a Collection of all the permutations of the specified Collection.
Returns an unmodifiable view of the sum of two multisets. In the returned multiset, the count of each element is the sum of its counts in the two backing multisets. The iteration order of the returned multiset matches that of the element set of this followed by the members of the element set of other that are not contained in other, with repeated occurrences of the same element appearing consecutively.
Returns a view of this that skips its first numberToSkip elements. If this contains fewer than numberToSkip elements, the returned iterable skips all of its elements.
Returns a new Multiset filled with all elements of this collection.
Returns a new MutableMultiset filled with all elements of this collection.