Collection interface

The root interface in the collection hierarchy. A collection represents a group of objects.

Add elements to a collection

ReturnMethodSummary
booleanadd(E e)Ensures that this collection contains the specified element (optional operation).
boolean addAll(Collection<? extends E> c) Adds all of the elements in the specified collection to this collection (optional operation).

Is it contained in the collection

ReturnMethodSummary
booleancontains(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.

Compare two collections

ReturnMethodSummary
booleanequals(Object o)Compares the specified object with this collection for equality.

Remove elements from a collection

ReturnMethodSummary
booleanremove(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 of 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).

Convert collection to Array

ReturnMethodSummary
Object[]toArray()Returns an array containing all of the elements in this collection.
<T> T[] toArray(T[] 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.

Get the size of a Collection

ReturnMethodSummary
intsize()Returns the number of elements in this collection.

Is a collection empty

ReturnMethodSummary
booleanisEmpty()Returns true if this collection contains no elements.

Clear a collection

ReturnMethodSummary
voidclear()Removes all of the elements from this collection (optional operation).

Get the iterator() from a collection

ReturnMethodSummary
Iterator<E>iterator()Returns an iterator over the elements in this collection.
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.