The generic class Bag is a balanced binary set with support for duplicate keys. The generic has a single type parameter, T - the data type of the bag. The generic class Bag exists in the namespace calculus (in assembly calculus.jar).
When creating a bag Bag<T>, the key class T is expected to be comparable. There are three ways in which the comparator for class T can be specified:
The declaration of the bag class (in Java) is shown below.
public class Bag<T> implements Collection<T>
Searches, insertions and removals are O(log2n).
When for is applied to a bag, the entries are presented in key order.