Package dsa

Interface Bag<T>

Type Parameters:
T - the type of items in the bag.
All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
LinkedBag, ResizingArrayBag

public interface Bag<T> extends Iterable<T>
This interface specifies the API for the bag data structure.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T item)
    Adds item to this bag.
    boolean
    Returns true if this bag is empty, and false otherwise.
    int
    Returns the number of items in this bag.
    Returns a string representation of this bag.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • isEmpty

      boolean isEmpty()
      Returns true if this bag is empty, and false otherwise.
      Returns:
      true if this bag is empty, and false otherwise.
    • size

      int size()
      Returns the number of items in this bag.
      Returns:
      number of items in this bag.
    • add

      void add(T item)
      Adds item to this bag.
      Parameters:
      item - the item.
    • toString

      String toString()
      Returns a string representation of this bag.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this bag.