DthingApi
Public Member Functions | List of all members
java.util.Collection< E > Interface Template Reference
Inheritance diagram for java.util.Collection< E >:
java.util.AbstractCollection< E > java.util.List< E > java.util.Queue< E > java.util.Set< E > java.util.AbstractList< E > java.util.AbstractQueue< E > java.util.AbstractSet< E > java.util.AbstractList< E > java.util.ArrayList< E > java.util.Vector< E > java.util.AbstractQueue< E > java.util.AbstractSet< E > java.util.HashSet< E >

Public Member Functions

boolean add (E object)
 
boolean addAll (Collection<? extends E > collection)
 
void clear ()
 
boolean contains (Object object)
 
boolean containsAll (Collection<?> collection)
 
boolean equals (Object object)
 
int hashCode ()
 
boolean isEmpty ()
 
Iterator< E > iterator ()
 
boolean remove (Object object)
 
boolean removeAll (Collection<?> collection)
 
boolean retainAll (Collection<?> collection)
 
int size ()
 
Object [] toArray ()
 

Detailed Description

Collection

is the root of the collection hierarchy. It defines operations on data collections and the behavior that they will have in all implementations of

Collection

s.

All direct or indirect implementations of

Collection

should implement at least two constructors. One with no parameters which creates an empty collection and one with a parameter of type

Collection

. This second constructor can be used to create a collection of different type as the initial collection but with the same elements. Implementations of

Collection

cannot be forced to implement these two constructors but at least all implementations under

do.

Methods that change the content of a collection throw an

UnsupportedOperationException

if the underlying collection does not support that operation, though it's not mandatory to throw such an

Exception

in cases where the requested operation would not change the collection. In these cases it's up to the implementation whether it throws an

UnsupportedOperationException

or not.

Methods marked with (optional) can throw an

UnsupportedOperationException

if the underlying collection doesn't support that method.

Member Function Documentation

◆ add()

boolean java.util.Collection< E >.add ( object)

Attempts to add

object

to the contents of this

Collection

(optional).

After this method finishes successfully it is guaranteed that the object is contained in the collection.

If the collection was modified it returns

true

,

false

if no changes were made.

An implementation of

Collection

may narrow the set of accepted objects, but it has to specify this in the documentation. If the object to be added does not meet this restriction, then an

IllegalArgumentException

is thrown.

If a collection does not yet contain an object that is to be added and adding the object fails, this method must throw an appropriate unchecked Exception. Returning false is not permitted in this case because it would violate the postcondition that the element will be part of the collection after this method finishes.

Parameters
objectthe object to add.
Returns
true
if this
Collection
is modified,
false
otherwise.
Exceptions
UnsupportedOperationExceptionif adding to this
Collection
is not supported.
ClassCastExceptionif the class of the object is inappropriate for this collection.
IllegalArgumentExceptionif the object cannot be added to this
Collection
.
NullPointerExceptionif null elements cannot be added to the
Collection
.

Implemented in java.util.AbstractList< E >, java.util.Vector< E >, java.util.Queue< E >, java.util.ArrayList< E >, java.util.HashSet< E >, java.util.List< E >, java.util.AbstractQueue< E >, java.util.Set< E >, and java.util.AbstractCollection< E >.

◆ addAll()

boolean java.util.Collection< E >.addAll ( Collection<? extends E >  collection)

Attempts to add all of the objects contained in

Collection

to the contents of this

Collection

(optional). If the passed

Collection

is changed during the process of adding elements to this

Collection

, the behavior is not defined.

Parameters
collectionthe
Collection
of objects.
Returns
true
if this
Collection
is modified,
false
otherwise.
Exceptions
UnsupportedOperationExceptionif adding to this
Collection
is not supported.
ClassCastExceptionif the class of an object is inappropriate for this
Collection
.
IllegalArgumentExceptionif an object cannot be added to this
Collection
.
NullPointerExceptionif
collection
is
null
, or if it contains
null
elements and this
Collection
does not support such elements.

Implemented in java.util.Vector< E >, java.util.ArrayList< E >, java.util.AbstractQueue< E >, java.util.List< E >, java.util.AbstractCollection< E >, and java.util.Set< E >.

◆ clear()

void java.util.Collection< E >.clear ( )

Removes all elements from this

Collection

, leaving it empty (optional).

Exceptions
UnsupportedOperationExceptionif removing from this
Collection
is not supported.
See also
isEmpty
size

Implemented in java.util.AbstractList< E >, java.util.ArrayList< E >, java.util.Vector< E >, java.util.List< E >, java.util.AbstractQueue< E >, java.util.AbstractCollection< E >, java.util.HashSet< E >, and java.util.Set< E >.

◆ contains()

boolean java.util.Collection< E >.contains ( Object  object)

Tests whether this

Collection

contains the specified object. Returns

true

if and only if at least one element

elem

in this

Collection

meets following requirement:

(object==null ? elem==null : object.equals(elem))

.

Parameters
objectthe object to search for.
Returns
true
if object is an element of this
Collection
,
false
otherwise.
Exceptions
ClassCastExceptionif the object to look for isn't of the correct type.
NullPointerExceptionif the object to look for is
null
and this
Collection
doesn't support
null
elements.

Implemented in java.util.ArrayList< E >, java.util.Vector< E >, java.util.List< E >, java.util.AbstractCollection< E >, java.util.HashSet< E >, and java.util.Set< E >.

◆ containsAll()

boolean java.util.Collection< E >.containsAll ( Collection<?>  collection)

Tests whether this

Collection

contains all objects contained in the specified

Collection

. If an element

elem

is contained several times in the specified

Collection

, the method returns

true

even if

elem

is contained only once in this

Collection

.

Parameters
collectionthe collection of objects.
Returns
true
if all objects in the specified
Collection
are elements of this
Collection
,
false
otherwise.
Exceptions
ClassCastExceptionif one or more elements of
collection
isn't of the correct type.
NullPointerExceptionif
collection
contains at least one
null
element and this
Collection
doesn't support
null
elements.
NullPointerExceptionif
collection
is
null
.

Implemented in java.util.Vector< E >, java.util.AbstractCollection< E >, java.util.List< E >, and java.util.Set< E >.

◆ equals()

boolean java.util.Collection< E >.equals ( Object  object)

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.

Parameters
objectthe object to compare with this object.
Returns
true
if the object is the same as this object and
false
if it is different from this object.
See also
hashCode

Implemented in java.util.ArrayList< E >, java.util.AbstractList< E >, java.util.Vector< E >, java.util.List< E >, java.util.Set< E >, and java.util.AbstractSet< E >.

◆ hashCode()

int java.util.Collection< E >.hashCode ( )

Returns an integer hash code for the receiver. Objects which are equal return the same value for this method.

Returns
the receiver's hash.
See also
equals

Implemented in java.util.ArrayList< E >, java.util.AbstractList< E >, java.util.Vector< E >, java.util.List< E >, java.util.Set< E >, and java.util.AbstractSet< E >.

◆ isEmpty()

boolean java.util.Collection< E >.isEmpty ( )

Returns if this

Collection

contains no elements.

Returns
true
if this
Collection
has no elements,
false
otherwise.
See also
size

Implemented in java.util.Vector< E >, java.util.ArrayList< E >, java.util.List< E >, java.util.AbstractCollection< E >, java.util.HashSet< E >, and java.util.Set< E >.

◆ iterator()

Iterator<E> java.util.Collection< E >.iterator ( )

Returns an instance of Iterator that may be used to access the objects contained by this

Collection

. The order in which the elements are returned by the iterator is not defined. Only if the instance of the

Collection

has a defined order the elements are returned in that order.

Returns
an iterator for accessing the
Collection
contents.

Implemented in java.util.AbstractList< E >, java.util.ArrayList< E >, java.util.List< E >, java.util.AbstractCollection< E >, java.util.HashSet< E >, and java.util.Set< E >.

◆ remove()

boolean java.util.Collection< E >.remove ( Object  object)

Removes one instance of the specified object from this

Collection

if one is contained (optional). The element

elem

that is removed complies with

(object==null ? elem==null : object.equals(elem)

.

Parameters
objectthe object to remove.
Returns
true
if this
Collection
is modified,
false
otherwise.
Exceptions
UnsupportedOperationExceptionif removing from this
Collection
is not supported.
ClassCastExceptionif the object passed is not of the correct type.
NullPointerExceptionif
object
is
null
and this
Collection
doesn't support
null
elements.

Implemented in java.util.Vector< E >, java.util.ArrayList< E >, java.util.List< E >, java.util.AbstractCollection< E >, java.util.HashSet< E >, and java.util.Set< E >.

◆ removeAll()

boolean java.util.Collection< E >.removeAll ( Collection<?>  collection)

Removes all occurrences in this

Collection

of each object in the specified

Collection

(optional). After this method returns none of the elements in the passed

Collection

can be found in this

Collection

anymore.

Parameters
collectionthe collection of objects to remove.
Returns
true
if this
Collection
is modified,
false
otherwise.
Exceptions
UnsupportedOperationExceptionif removing from this
Collection
is not supported.
ClassCastExceptionif one or more elements of
collection
isn't of the correct type.
NullPointerExceptionif
collection
contains at least one
null
element and this
Collection
doesn't support
null
elements.
NullPointerExceptionif
collection
is
null
.

Implemented in java.util.Vector< E >, java.util.AbstractCollection< E >, java.util.List< E >, java.util.Set< E >, and java.util.AbstractSet< E >.

◆ retainAll()

boolean java.util.Collection< E >.retainAll ( Collection<?>  collection)

Removes all objects from this

Collection

that are not also found in the

Collection

passed (optional). After this method returns this

Collection

will only contain elements that also can be found in the

Collection

passed to this method.

Parameters
collectionthe collection of objects to retain.
Returns
true
if this
Collection
is modified,
false
otherwise.
Exceptions
UnsupportedOperationExceptionif removing from this
Collection
is not supported.
ClassCastExceptionif one or more elements of
collection
isn't of the correct type.
NullPointerExceptionif
collection
contains at least one
null
element and this
Collection
doesn't support
null
elements.
NullPointerExceptionif
collection
is
null
.

Implemented in java.util.Vector< E >, java.util.AbstractCollection< E >, java.util.List< E >, and java.util.Set< E >.

◆ size()

int java.util.Collection< E >.size ( )

Returns a count of how many objects this

Collection

contains.

Returns
how many objects this
Collection
contains, or Integer.MAX_VALUE if there are more than Integer.MAX_VALUE elements in this
Collection
.

Implemented in java.util.Vector< E >, java.util.AbstractCollection< E >, java.util.ArrayList< E >, java.util.List< E >, java.util.Set< E >, and java.util.HashSet< E >.

◆ toArray()

Object [] java.util.Collection< E >.toArray ( )

Returns a new array containing all elements contained in this

Collection

.

If the implementation has ordered elements it will return the element array in the same order as an iterator would return them.

The array returned does not reflect any changes of the

Collection

. A new array is created even if the underlying data structure is already an array.

Returns
an array of the elements from this
Collection
.

Implemented in java.util.Vector< E >, java.util.ArrayList< E >, java.util.AbstractCollection< E >, java.util.List< E >, and java.util.Set< E >.


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