E - the type of the elements in the bag.public final class HashBag<E> extends AbstractBag<E> implements Serializable
Bag implementation based on HashMap. This implementation
accepts null elements. Instances of this class are not thread-safe.| Constructor and Description |
|---|
HashBag()
Creates a new empty
HashBag. |
HashBag(Collection<? extends E> c)
Creates a new
HashBag using the elements contained in the
given Collection. |
HashBag(E... elements)
Creates a new
HashBag using the elements contained in the
given array. |
HashBag(int initialCapacity)
Creates a new empty
HashBag having the given initial capacity. |
HashBag(Iterable<? extends E> i)
Creates a new
HashBag using the elements contained in the
given Iterable. |
HashBag(Iterator<? extends E> i)
Creates a new
HashBag using the elements contained in the
given Iterator. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e) |
void |
clear() |
boolean |
contains(Object o) |
int |
count(E e)
Returns the count of the given element in this bag.
|
Iterator<E> |
iterator() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
int |
size() |
equals, hashCodeaddAll, containsAll, isEmpty, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddAll, containsAll, isEmpty, retainAll, toArray, toArraypublic HashBag()
HashBag.public HashBag(int initialCapacity)
HashBag having the given initial capacity.initialCapacity - the bag's initial capacity.IllegalArgumentException - if initialCapacity < 0.public HashBag(Collection<? extends E> c)
HashBag using the elements contained in the
given Collection.c - the collection to use to populate the created bag.NullPointerException - if c is null.public HashBag(Iterable<? extends E> i)
HashBag using the elements contained in the
given Iterable.i - the iterable to use to populate the created bag.NullPointerException - if i is null.public HashBag(Iterator<? extends E> i)
HashBag using the elements contained in the
given Iterator.i - the iterator to use to populate the created bag.NullPointerException - if i is null.public HashBag(E... elements)
HashBag using the elements contained in the
given array.elements - the elements to use to populate the created bag.NullPointerException - if elements is null.public boolean add(E e)
add in interface Collection<E>add in class AbstractCollection<E>public void clear()
clear in interface Collection<E>clear in class AbstractCollection<E>public boolean contains(Object o)
contains in interface Collection<E>contains in class AbstractCollection<E>public int count(E e)
Bagpublic Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in class AbstractCollection<E>public boolean remove(Object o)
remove in interface Collection<E>remove in class AbstractCollection<E>public boolean removeAll(Collection<?> c)
removeAll in interface Collection<E>removeAll in class AbstractCollection<E>public int size()
size in interface Collection<E>size in class AbstractCollection<E>Copyright © 2012–2015. All rights reserved.