public class Bag
extends java.lang.Object
Constructor and Description |
---|
Bag(int capacity)
non-default constructor
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String value)
inserts a new String into this Bag
|
int |
capacity()
Returns amount of space this bag has
|
void |
clear()
Empties out Bag
|
boolean |
contains(java.lang.String value)
Determines if Bag contains the specified string
|
Bag |
copy()
Return a bag that is an exact duplicate of this Bag
|
boolean |
equals(Bag otherBag)
Returns True if this Bag is equal to Bag given in parameter.
|
boolean |
isEmpty()
Returns True if Bag empty; else returns False
|
void |
remove(java.lang.String value)
Deletes specified string from Bag.
|
java.lang.String |
removeRandom()
Remove and returns a random string from the Bag.
|
int |
size()
Returns number of strings in Bag
|
java.lang.String |
toString()
Returns Bag as a printable String
|
void |
trimToSize()
Make this Bag's capacity equal to its size
|
Bag |
union(Bag otherBag)
Return union of this Bag and Bag specified in parameter
|
public Bag(int capacity)
capacity
- amount of storage space this bag haspublic void add(java.lang.String value)
value
- string to be insertedpublic void remove(java.lang.String value)
value
- string to removepublic boolean contains(java.lang.String value)
value
- string to search forpublic boolean isEmpty()
public void clear()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public int capacity()
public java.lang.String removeRandom()
public boolean equals(Bag otherBag)
otherBag
- bag to compare to this bagpublic Bag copy()
public void trimToSize()