|
| |
| Java Collection Framework - Collection Interface |
The Collection interface is used to
represent any group of ojects, or
elements. Here is a list of the public
methods of the Collection Interface.
boolean
|
add (Object o)
Ensures that this collection
contains the specified element
(optional operation).
|
boolean
|
addAll(Collection c)
Adds all of the elements in
the specified collection to
this collection (optional operation).
|
void
|
clear()
Removes all of the elements
from this collection (optional
operation).
|
boolean
|
contains(Object o)
Returns true if this collection contains the specified
element.
|
boolean
|
containsAll(Collection c)
Returns true if this collection contains all of
the elements in the specified
collection.
|
boolean
|
equals(Object o)
Compares the specified object
with this collection for equality.
|
int
|
hashCode()
Returns the hash code value
for this collection.
|
boolean
|
isEmpty()
Returns true if this collection contains no elements.
|
Iterator
|
iterator()
Returns an iterator over the elements in this collection.
|
boolean
|
remove(Object o)
Removes a single instance of
the specified element from this
collection, if it is present
(optional operation).
|
boolean
|
removeAll(Collection c)
Removes all this collection's
elements that are also contained
in the specified collection
(optional operation).
|
boolean
|
retainAll(Collection c)
Retains only the elements in
this collection that are contained
in the specified collection
(optional operation).
|
int
|
size()
Returns the number of elements
in this collection.
|
Object[]
|
toArray()
Returns an array containing
all of the elements in this
collection.
|
Object[]
|
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.
|
The
interface supports basic operations
like adding and removing. When you
try to remove an element, only a single
instance of the element in the collection
is removed, if present.
boolean add (Object o)
boolean remove(Object o)
The
Collection interface also supports
query operations
int size()
boolean isEmpty()
boolean contains(Object o)
Iterator iterator()
Explore the other Interface and Classes
of Java Collection Framework
Collection
Interface
Iterator
Interface
Set
Interface
List
Interface
ListIterator
Interface
Map
Interface
SortedSet
Interface
SortedMap
Interface
HashSet
& TreeSet Classes
ArrayList
& LinkedList Classes
HashMap
& Treemap Classes
Vector
and Stack Classes
|
|