# Package org.apache.commons.collections4.bag

package org.apache.commons.collections4.bag
Implements the `Bag` and `SortedBag` interfaces. A bag stores an object and a count of the number of occurrences of the object.

The following implementations are provided in the package:

- HashBag - implementation that uses a HashMap to store the data
- TreeBag - implementation that uses a TreeMap to store the data

The following decorators are provided in the package:

- Synchronized - synchronizes method access for multithreaded environments
- Unmodifiable - ensures the bag cannot be altered
- Predicated - ensures that only elements that are valid according to a predicate can be added
- Transformed - transforms each element added to the bag
- Collection - ensures compliance with the java.util.Collection contract

This package is deprecated since 4.6.0; use the `org.apache.commons.collections4.multiset` package instead. See the `Bag` Javadoc for migration notes.

- Related Packages
  Package
  Description
  org.apache.commons.collections4
  Interfaces and utilities shared across all packages.
- Classes
  Class
  Description
  AbstractBagDecorator<E>
  Deprecated.
  Since 4.6.0, use `AbstractMultiSetDecorator` instead.
  AbstractMapBag<E>
  Deprecated.
  Since 4.6.0, use `AbstractMapMultiSet` instead.
  AbstractMapBag.MutableInteger
  Mutable integer class for storing the data.
  AbstractSortedBagDecorator<E>
  Deprecated.
  Since 4.6.0, use `AbstractSortedMultiSetDecorator` instead.
  CollectionBag<E>
  Deprecated.
  Since 4.6.0, no longer needed; a `MultiSet` already complies with the `Collection` contract.
  CollectionSortedBag<E>
  Deprecated.
  Since 4.6.0, no longer needed; a `SortedMultiSet` already complies with the `Collection` contract.
  HashBag<E>
  Deprecated.
  Since 4.6.0, use `HashMultiSet` instead.
  PredicatedBag<E>
  Deprecated.
  Since 4.6.0, use `PredicatedMultiSet` instead.
  PredicatedSortedBag<E>
  Deprecated.
  Since 4.6.0, use `PredicatedSortedMultiSet` instead.
  SynchronizedBag<E>
  Deprecated.
  Since 4.6.0, use `SynchronizedMultiSet` instead.
  SynchronizedSortedBag<E>
  Deprecated.
  Since 4.6.0, use `SynchronizedSortedMultiSet` instead.
  TransformedBag<E>
  Deprecated.
  Since 4.6.0, use `TransformedMultiSet` instead.
  TransformedSortedBag<E>
  Deprecated.
  Since 4.6.0, use `TransformedSortedMultiSet` instead.
  TreeBag<E>
  Deprecated.
  Since 4.6.0, use `TreeMultiSet` instead.
  UnmodifiableBag<E>
  Deprecated.
  Since 4.6.0, use `UnmodifiableMultiSet` instead.
  UnmodifiableSortedBag<E>
  Deprecated.
  Since 4.6.0, use `UnmodifiableSortedMultiSet` instead.