Back to index

plt-scheme  4.2.1
Public Member Functions
java.util.Collection Interface Reference

Interface that represents a collection of objects. More...

Inheritance diagram for java.util.Collection:
Inheritance graph
[legend]

List of all members.

Public Member Functions

boolean add (Object o)
 Add an element to this collection.
boolean addAll (Collection c)
 Add the contents of a given collection to this collection.
void clear ()
 Clear the collection, such that a subsequent call to isEmpty() would return true.
boolean contains (Object o)
 Test whether this collection contains a given object as one of its elements.
boolean containsAll (Collection c)
 Test whether this collection contains every element in a given collection.
boolean isEmpty ()
 Test whether this collection is equal to some object.
Iterator iterator ()
 Obtain an Iterator over this collection.
boolean remove (Object o)
 Remove a single occurrence of an object from this collection.
boolean removeAll (Collection c)
 Remove all elements of a given collection from this collection.
boolean retainAll (Collection c)
 Remove all elements of this collection that are not contained in a given collection.
int size ()
 Get the number of elements in this collection.
Object[] toArray ()
 Copy the current contents of this collection into an array.
Object[] toArray (Object[] a)
 Copy the current contents of this collection into an array.

Detailed Description

Interface that represents a collection of objects.

This interface is the root of the collection hierarchy, and does not provide any guarantees about the order of its elements or whether or not duplicate elements are permitted.

All methods of this interface that are defined to modify the collection are defined as optional. An optional operation may throw an UnsupportedOperationException if the data backing this collection does not support such a modification. This may mean that the data structure is immutable, or that it is read-only but may change ("unmodifiable"), or that it is modifiable but of fixed size (such as an array), or any number of other combinations.

A class that wishes to implement this interface should consider subclassing AbstractCollection, which provides basic implementations of most of the methods of this interface. Classes that are prepared to make guarantees about ordering or about absence of duplicate elements should consider implementing List or Set respectively, both of which are subinterfaces of Collection.

A general-purpose implementation of the Collection interface should in most cases provide at least two constructors: One which takes no arguments and creates an empty collection, and one which takes a Collection as an argument and returns a collection containing the same elements (that is, creates a copy of the argument using its own implementation).

Author:
Original author unknown
Eric Blake ebb9@.nosp@m.emai.nosp@m.l.byu.nosp@m..edu
See also:
List
Set
Map
SortedSet
SortedMap
HashSet
TreeSet
ArrayList
LinkedList
Vector
Collections
Arrays
AbstractCollection
Since:
1.2 updated to 1.4

Definition at line 86 of file Collection.java.


Member Function Documentation

Add an element to this collection.

Parameters:
othe object to add.
Returns:
true if the collection was modified as a result of this action.
Exceptions:
UnsupportedOperationExceptionif this collection does not support the add operation.
ClassCastExceptionif o cannot be added to this collection due to its type.
IllegalArgumentExceptionif o cannot be added to this collection for some other reason.

Implemented in java.util.AbstractList, java.util.List, and java.util.AbstractCollection.

Add the contents of a given collection to this collection.

Parameters:
cthe collection to add.
Returns:
true if the collection was modified as a result of this action.
Exceptions:
UnsupportedOperationExceptionif this collection does not support the addAll operation.
ClassCastExceptionif some element of c cannot be added to this collection due to its type.
IllegalArgumentExceptionif some element of c cannot be added to this collection for some other reason.

Implemented in java.util.SubList, java.util.AbstractList, java.util.List, and java.util.AbstractCollection.

Clear the collection, such that a subsequent call to isEmpty() would return true.

Exceptions:
UnsupportedOperationExceptionif this collection does not support the clear operation.

Implemented in java.util.AbstractList, java.util.List, and java.util.AbstractCollection.

Test whether this collection contains a given object as one of its elements.

Parameters:
othe element to look for.
Returns:
true if this collection contains at least one element e such that o == null ? e == null : o.equals(e).

Implemented in java.util.SubList, java.util.AbstractCollection, java.util.List, and java.util.AbstractList.

Here is the caller graph for this function:

Test whether this collection contains every element in a given collection.

Parameters:
cthe collection to test for.
Returns:
true if for every element o in c, contains(o) would return true.

Implemented in java.util.SubList, java.util.AbstractCollection, java.util.List, and java.util.AbstractList.

Test whether this collection is equal to some object.

The Collection interface does not explicitly require any behaviour from this method, and it may be left to the default implementation provided by Object. The Set and List interfaces do, however, require specific behaviour from this method.

If an implementation of Collection, which is not also an implementation of Set or List, should choose to implement this method, it should take care to obey the contract of the equals method of Object. In particular, care should be taken to return false when o is a Set or a List, in order to preserve the symmetry of the relation.

Parameters:
othe object to compare to this collection.
Returns:
true if the o is equal to this collection. Obtain a hash code for this collection. The Collection interface does not explicitly require any behaviour from this method, and it may be left to the default implementation provided by Object. The Set and List interfaces do, however, require specific behaviour from this method.

If an implementation of Collection, which is not also an implementation of Set or List, should choose to implement this method, it should take care to obey the contract of the hashCode method of Object. Note that this method renders it impossible to correctly implement both Set and List, as the required implementations are mutually exclusive.

Returns:
a hash code for this collection. Test whether this collection is empty, that is, if size() == 0.
true if this collection contains no elements.

Implemented in java.util.SubList, java.util.List, java.util.AbstractCollection, and java.util.AbstractList.

Obtain an Iterator over this collection.

Returns:
an Iterator over the elements of this collection, in any order.

Implemented in java.util.SubList, java.util.AbstractList, java.util.List, java.util.AbstractSequentialList, and java.util.AbstractCollection.

Here is the caller graph for this function:

Remove a single occurrence of an object from this collection.

That is, remove an element e, if one exists, such that o == null ? e == null : o.equals(e).

Parameters:
othe object to remove.
Returns:
true if the collection changed as a result of this call, that is, if the collection contained at least one occurrence of o.
Exceptions:
UnsupportedOperationExceptionif this collection does not support the remove operation.

Implemented in java.util.SubList, java.util.List, java.util.AbstractCollection, and java.util.AbstractList.

Remove all elements of a given collection from this collection.

That is, remove every element e such that c.contains(e).

Returns:
true if this collection was modified as a result of this call.
Exceptions:
UnsupportedOperationExceptionif this collection does not support the removeAll operation.

Implemented in java.util.SubList, java.util.List, java.util.AbstractCollection, and java.util.AbstractList.

Remove all elements of this collection that are not contained in a given collection.

That is, remove every element e such that !c.contains(e).

Returns:
true if this collection was modified as a result of this call.
Exceptions:
UnsupportedOperationExceptionif this collection does not support the retainAll operation.

Implemented in java.util.SubList, java.util.List, java.util.AbstractCollection, and java.util.AbstractList.

Get the number of elements in this collection.

Returns:
the number of elements in the collection.

Implemented in java.util.SubList, java.util.List, java.util.AbstractList, and java.util.AbstractCollection.

Here is the caller graph for this function:

Copy the current contents of this collection into an array.

Returns:
an array of type Object[] and length equal to the size of this collection, containing the elements currently in this collection, in any order.

Implemented in java.util.SubList, java.util.List, java.util.AbstractCollection, and java.util.AbstractList.

Object [] java.util.Collection.toArray ( Object[]  a)

Copy the current contents of this collection into an array.

If the array passed as an argument has length less than the size of this collection, an array of the same run-time type as a, and length equal to the size of this collection, is allocated using Reflection. Otherwise, a itself is used. The elements of this collection are copied into it, and if there is space in the array, the following element is set to null. The resultant array is returned. Note: The fact that the following element is set to null is only useful if it is known that this collection does not contain any null elements.

Parameters:
athe array to copy this collection into.
Returns:
an array containing the elements currently in this collection, in any order.
Exceptions:
ArrayStoreExceptionif the type of any element of the collection is not a subtype of the element type of a.

Implemented in java.util.SubList, java.util.List, java.util.AbstractCollection, and java.util.AbstractList.


The documentation for this interface was generated from the following file: