Java Collection

The Collections Framework is a way to manage objects as a group in a program, similar to an array. Collection was not included in the early versions of Java, but it was added in J2SE 1.2.

Collection Methods

The Collection interface includes common methods that can be used throughout the Collections Framework.

Method Description
boolean add(E e) Adds the object(e) at the end.
boolean addAll(Collection<? extends E> c) Adds a collection object.
void clear() Clears the Collection object.
boolean contains(Object o) Returns whether the object(o) entered in the Collection exists.
boolean equals(Object o) Returns whether it is the same as the entered Collection.
boolean isEmpty() Returns whether the Collection object is empty.
boolean remove(Object o) Deletes the entered object(o) and returns whether deletion succeeded.
int size() Returns the size of the Collection object.
Object[] toArray() Returns the objects held by the Collection as an array.
<T> T[] toArray(T array[]) Returns the objects held by the Collection as an array of the entered type.