Class AbstractSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
- All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
An AbstractSet is an abstract implementation of the Set interface. This
implementation does not support adding. A subclass must implement the
abstract methods iterator() and size().
- Since:
- 1.2
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new instance of this AbstractSet. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares the specified object to this Set and returns true if they are equal.inthashCode()Returns the hash code for this set.booleanremoveAll(Collection<?> collection) Removes all occurrences in this collection which are contained in the specified collection.Methods inherited from class AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toStringModifier and TypeMethodDescriptionbooleanAttempts to addobjectto the contents of thisCollection(optional).booleanaddAll(Collection<? extends E> collection) Attempts to add all of the objects contained incollectionto the contents of thisCollection(optional).voidclear()Removes all elements from thisCollection, leaving it empty (optional).booleanTests whether thisCollectioncontains the specified object.booleancontainsAll(Collection<?> collection) Tests whether thisCollectioncontains all objects contained in the specifiedCollection.booleanisEmpty()Returns if thisCollectioncontains no elements.iterator()Returns an instance ofIteratorthat may be used to access the objects contained by thisCollection.booleanRemoves one instance of the specified object from thisCollectionif one is contained (optional).booleanretainAll(Collection<?> collection) Removes all objects from thisCollectionthat are not also found in theCollectionpassed (optional).abstract intsize()Returns a count of how many objects thisCollectioncontains.Object[]toArray()Returns a new array containing all elements contained in thisArrayList.<T> T[]toArray(T[] contents) Returns an array containing all elements contained in thisArrayList.toString()Returns the string representation of thisCollection.Methods inherited from class Object
clone, getClass, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()final ClassgetClass()Returns the runtime class of an object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.final voidwait()Causes current thread to wait until another thread invokes the method or the method for this object.final voidwait(long timeout) Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.final voidwait(long timeout, int nanos) Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.Methods inherited from interface Set
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArrayModifier and TypeMethodDescriptionbooleanAdds the specified object to this set.booleanaddAll(Collection<? extends E> collection) Adds the objects in the specified collection which do not exist yet in this set.voidclear()Removes all elements from this set, leaving it empty.booleanSearches this set for the specified object.booleancontainsAll(Collection<?> collection) Searches this set for all objects in the specified collection.booleanisEmpty()Returns true if this set has no elements.iterator()Returns an iterator on the elements of this set.booleanRemoves the specified object from this set.booleanretainAll(Collection<?> collection) Removes all objects from this set that are not contained in the specified collection.intsize()Returns the number of elements in this set.Object[]toArray()Returns an array containing all elements contained in this set.<T> T[]toArray(T[] array) Returns an array containing all elements contained in this set.
-
Constructor Details
-
AbstractSet
protected AbstractSet()Constructs a new instance of this AbstractSet.
-
-
Method Details
-
equals
Compares the specified object to this Set and returns true if they are equal. The object must be an instance of Set and contain the same objects. -
hashCode
public int hashCode()Returns the hash code for this set. Two set which are equal must return the same value. This implementation calculates the hash code by adding each element's hash code. -
removeAll
Removes all occurrences in this collection which are contained in the specified collection.- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractCollection<E>- Parameters:
collection- the collection of objects to remove.- Returns:
trueif this collection was modified,falseotherwise.- Throws:
UnsupportedOperationException- if removing from this collection is not supported.
-