| Classic JavaDoc |
Class AbstractCollection
java.lang.Object └ java.util.AbstractCollection
Implemented Interfaces:
Direct Known Subclasses:
public abstract class AbstractCollection implements Collection
To implement an unmodifiable collection, the programmer needs only to extend this class and provide implementations for the iterator and size methods. (The iterator returned by the iterator method must implement hasNext and next.)
To implement a modifiable collection, the programmer must additionally override this class's add method (which otherwise throws an UnsupportedOperationException), and the iterator returned by the iterator method must additionally implement its remove method.
The programmer should generally provide a void (no argument) and Collection constructor, as per the recommendation in the Collection interface specification.
The documentation for each non-abstract methods in this class describes its implementation in detail. Each of these methods may be overridden if the collection being implemented admits a more efficient implementation.
This class is a member of the Java Collections Framework.
Constructors
protected | AbstractCollection () | |
Sole constructor. (For invocation by subclass constructors, typically implicit.) |
Methods
boolean | add (Object o) | |
Ensures that this collection contains the specified element (optional operation). Returns true if the collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.) Collections that support this op ... more > |
boolean | addAll (Collection c) | |
Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the speci ... more > |
void | clear () | |
Removes all of the elements from this collection (optional operation). The collection will be empty after this call returns (unless it throws an exception). This implementation iterates over this collection, removing each element using the Iterator.remove operation. Most implementa ... more > |
boolean | contains (Object o) | |
Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)). This implementation iterates over the elements in the collection, checking each el ... more > |
boolean | containsAll (Collection c) | |
Returns true if this collection contains all of the elements in the specified collection. This implementation iterates over the specified collection, checking each element returned by the iterator in turn to see if it's contained in this collection. If all elements are so contained ... more > |
boolean | isEmpty () | |
Returns true if this collection contains no elements. This implementation returns size() == 0. |
abstract Iterator | iterator () | |
Returns an iterator over the elements contained in this collection. |
boolean | remove (Object o) | |
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the collection contains one or more such elements. Returns true if the collection contai ... more > |
boolean | removeAll (Collection c) | |
Removes from this collection all of its elements that are contained in the specified collection (optional operation). This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If i ... more > |
boolean | retainAll (Collection c) | |
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection. This implementation iterates over this collection, ... more > |
abstract int | size () | |
Returns the number of elements in this collection. If the collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. |
| toArray () | ||
Returns an array containing all of the elements in this collection. If the collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array will be "safe" in that no references to it ... more > |
| toArray (Object a) | ||
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specifie ... more > |
| toString () | ||
Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). ... more > |
Inherited methods
Community comments
Powered by JavaDocPlus