Collection Interface
Home ] Up ] [ Collection Interface ] List Interface ] Iterator Interface ] ListIterator Interface ] ArrayList/Iterator Example ] LinkedList Example ] Stack Class ]

 

 

The Collection interface (not to be confused with the Collections class -- see later) defines the top-level methods for all collection objects (that is, all objects that implement the Collection interface).  

Collection
    List
    Set
        SortedSet
Comparable (in java.lang package)
Comparator
Enumeration
Iterator
    ListIterator
Map
    SortedMap

It defines the following methods (this is the original source, minus many comments):

package java.util;

public interface Collection 
{
    // Query Operations

    int size();
    boolean isEmpty();
    boolean contains(Object o);
    Iterator iterator();
    Object[] toArray();
    Object[] toArray(Object a[]);

    // Modification Operations

    boolean add(Object o);
    boolean remove(Object o);

    // Bulk Operations

    boolean containsAll(Collection c);
    boolean addAll(Collection c);
    boolean removeAll(Collection c);
    boolean retainAll(Collection c);
    void clear();

    // Comparison and hashing

    boolean equals(Object o);
    int hashCode();
}

Note that the Collection interface itself does not enforce any policy, such as no duplicates or ordering.  Such policies are enforced by sub-interfaces of the Collection interface.

 

This page was last modified on 02 October, 2007