|
APCS Java Subset | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectap.java.util.HashSet
This collection implements the Set interface
using a hash table so that add, remove,
and contains each execute in constant or O(1) time
assuming reasonable distribution of elements by their hashCode
values.
The HashSet class is only used in the AB
course.
The order in which elements are returned by a
HashSet's iterator is not specified. It is possible
that the order will change during a program's execution if the
internal hash table is restructured, e.g., if it gets too full.
Iterating over elements requires time proportional to the number of
elements stored in the HashSet plus the capacity or
number of buckets used in the internal hash table.
Though not part of the AP Java subset, a HashSet
object can be constructed by specifying the initial number of
buckets (the capacity) and the load factor determining when
all elements are re-hashed. See the regular JDK API for details.
| Constructor Summary | |
HashSet()
Construct an initially empty set with the default capacity and load factor. |
|
| Method Summary | |
boolean |
add(java.lang.Object o)
Adds the parameter as an element to this set if it is not already stored in this set. |
boolean |
contains(java.lang.Object o)
Returns true if this set contains the element
passed as an argument,
otherwise returns false. |
Iterator |
iterator()
Returns an Iterator that provides access to the
the elements of this set. |
boolean |
remove(java.lang.Object o)
Removes the argument from this set and returns true
if the argument is in this set;
if not present returns false. |
int |
size()
Returns the number of elements in this set. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public HashSet()
| Method Detail |
public boolean add(java.lang.Object o)
Settrue. If the element
is not added because it is already stored in the set, the
function returns false.
add in interface Seto - is the element to be added to this set
true if o is added, false if
not added because it is already in the setpublic boolean contains(java.lang.Object o)
Settrue if this set contains the element
passed as an argument,
otherwise returns false.
More specifically, returns true if this set
contains an element e such that
e.equals(o).
contains in interface Seto - is the element being tested for inclusion in this set
true if this set contains the argument,
and false if the argument is not in this set.public boolean remove(java.lang.Object o)
Settrue
if the argument is in this set;
if not present returns false.
remove in interface Seto - is the element to be removed from this set
true if element is removed, otherwise return
falsepublic int size()
Set
size in interface Setpublic Iterator iterator()
Iterator that provides access to the
the elements of this set. Elements are returned in no
particular order.
iterator in interface Set
|
unofficial documentation for the APCS Java Subset | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||