0% found this document useful (0 votes)
2 views4 pages

Java Collections

The document explains the concept of collections as containers that group multiple objects, detailing the Collections Framework in Java, including the Collection and List interfaces. It highlights the unique characteristics of the List interface, such as ordered collections and the use of ListIterators for bidirectional access. Additionally, it discusses the Map interface, which stores key/value pairs and emphasizes the importance of the get() and put() methods for data retrieval and storage.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Java Collections

The document explains the concept of collections as containers that group multiple objects, detailing the Collections Framework in Java, including the Collection and List interfaces. It highlights the unique characteristics of the List interface, such as ordered collections and the use of ListIterators for bidirectional access. Additionally, it discusses the Map interface, which stores key/value pairs and emphasizes the importance of the get() and put() methods for data retrieval and storage.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

 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.

You might also like