The Collections Framework is made up
of a set of interfaces for storing and manipulating groups of data
into a single unit. It consists
of several interfaces, and classes that implement those interfaces, contained within the java.util
package. It provides tools for maintaining a data container of objects.
Different interfaces describe different types of functionalities.
The following diagrams shows the framework of core collection interfaces hierarchy.
Table of the ordered and unordered Collection
interfaces shown as:
|Interface name||Ordered||Allows duplicates||Maps key to object|
The Collection interface
is the root interface for the Java collections hierarchy. It is extended
by the List, Set, and the SortedSet interfaces. The Collection
interface is used to represent a group of
objects, or elements. Typically, it represents
data items that form a natural group. Some collection allows duplicate elements
while others do not. It consists of both ordered and unordered elements.
The declaration of the Collection interface is shown as:
public interface Collection<E>..
The <E> syntax tells that, the declared interface is a generic
interface i.e. when you declare a Collection instance you should specify the type of object contained in the collection.
This 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 it is available.
Following methods can be used for adding and deleting an element respectively.
boolean add(Object element)
boolean remove(Object element)
The list of other methods belonging to the Collection interface is shown in the table given below
| add(E o)
|| Adds the specified element to this set if it is not already present (optional operation).
|clear()||Removes all of the elements from this set (optional operation).|
|contains(Object o)||Returns true if this set contains the specified element.|
|equals(Object o)||Compares the specified object with this set for equality.|
|hashCode()||Returns the hash code value for this set.|
|isEmpty()||Returns true if this set contains no elements.|
|iterator()||Returns an iterator over the elements in this set.|
|remove(Object o)||Removes the specified element from this set if it is present (optional operation).|
|size()||Returns the number of elements in this set (its cardinality).|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.