A collection is basically a container that groups multiple objects into a single unit.
Examples include a list of employees, a set of numbers, a set of processes, a queue of
requests, favorite songs stored on smartphone or media player, contacts list etc.
collection is a data structure—actually, an object—that can hold references to other objects
that is used to store, retrieve, manipulate and communicate aggregate data.
Collections Framework:
Implementation classes are provided in [Link] and [Link]. concurrent package.
Collection Interface:
The root interface in the hierarchy is Collection interface. It represents a general group of
objects, called elements.
Collection extends the Iterable interface.
It has provided the methods common to every implementation class
It has provided the methods common to every implementation class
List Interface:
The List interface extends Collection Interface.
lists are ordered collection and allow duplicate elements.
In addition to the methods defined by Collection, List defines some of its own additional
methods for positional (indexed) access to list elements. List indices start from zero.
In addition to normal Iterator, List interface provides a special iterator, called a ListIterator,
that allows element insertion and replacement, and bidirectional access.
List Interface Methods:
List Interface – implementation classes:
Linked List class:
LinkedList class methods:
Map Interface:
Maps are part of the Collections Framework but are not, themselves, collections because
they do not implement the Collection interface.
Instead of storing groups of objects, maps store key/value pairs. A defining characteristic of a
map is its ability to retrieve a value given its key.
Maps associate keys to values. The keys in a Map must be unique, but the associated values
need not be.
In Map, both keys and values are objects.
Map Interface methods:
Note:
Pay special attention to get( ) and put( ). To store a value in a map, use put( ), specifying the key and
the value. To obtain a value, call get( ), passing the key as an argument. The value is returned. Thus,
get( ) and put( ) define the fundamental storage and retrieval methods used by all Map
implementations.