Collection Interface

Collection Interface: 

The root interface in the collection hierarchy. It represents a group of objects known as its elements.

  • It the part of java.util package.
  • The root interface in the collection hierarchy. It represents a group of individual objects as a single entity known as its elements.
  • The collection interface is a part of the core framework that provides the base for all the collection types. It defined the most common methods which are applicable for any collection object. 
  • It is an interface provided by JAVA along with JDK 1.2 version.

Key Interfaces Of Collection Framework

  • Collection
  • List
  • Set
  • Sorted Set
  • Navigable Set
  • Queue, Dequeue
  • Navigable Map
  • Sorted Map
  • Map

NOTE

Maps are not the part of the Collection Framework because there is no relation between Maps and Collection and Maps not implement the Collection interaface
#

Methods In Collection Interface

MethodDescription
boolean add(E e)Add the specified element in the collection.
boolean addAll(Collection<? extends E> c)Adds all of the elements in the specified collection to this collection.
void clear()Removes all of the elements from this collection.
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 content equality.
int hashCode()Returns the hash code value for this collection.
boolean isEmpty()Returns true if this collection contains no elements.
Iterator<E> 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.
boolean removeAll(Collection<?> c)Removes all of this collection's elements that are also contained in the specified collection.
boolean retainAll(Collection<?> c)

Retains only the elements in this collection that are contained in the specified collection. 

(Intersection between two collection)

int size()Returns the number of elements in this collection.
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.
boolean equals(Object o)

Compares the specified object with this collection for content equality.

boolean isEmpty()

Returns true if this collection contains no elements.

boolean add(E e)

Add the specified element in the collection.

boolean remove(Object o)

Removes a single instance of the specified element from this collection, if it is present.

boolean removeAll(Collection<?> c)

Removes all of this collection's elements that are also contained in the specified collection.

boolean addAll(Collection<? extends E> c)

Adds all of the elements in the specified collection to this collection.

void clear()

Removes all of the elements from this collection.

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.