Java - Collections Framework
Java - Collections Framework
Prior to Java 2, Java provided ad hoc classes such as Dictionary, Vector, Stack, and
Properties to store and manipulate groups of objects. Although these classes were quite useful,
they lacked a central, unifying theme. Thus, the way that you used Vector was different from the
way that you used Properties.
The framework had to allow different types of collections to work in a similar manner
and with a high degree of interoperability.
Interfaces − These are abstract data types that represent collections. Interfaces allow
collections to be manipulated independently of the details of their representation. In
object-oriented languages, interfaces generally form a hierarchy.
The collections framework defines several interfaces. This section provides an overview of each
interface −
https://www.tutorialspoint.com/java/java_collections.htm 1/7
15/04/2022, 16:17 Java - Collections Framework
3 The Set
This extends Collection to handle sets, which must contain unique elements.
4 The SortedSet
This extends Set to handle sorted sets.
5 The Map
This maps unique keys to values.
6 The Map.Entry
This describes an element (a key/value pair) in a map. This is an inner class of Map.
7 The SortedMap
This extends Map so that the keys are maintained in an ascending order.
8 The Enumeration
This is legacy interface defines the methods by which you can enumerate (obtain
one at a time) the elements in a collection of objects. This legacy interface has been
superceded by Iterator.
Java provides a set of standard collection classes that implement Collection interfaces. Some of
the classes provide full implementations that can be used as-is and others are abstract class,
providing skeletal implementations that are used as starting points for creating concrete
collections.
https://www.tutorialspoint.com/java/java_collections.htm 2/7
15/04/2022, 16:17 Java - Collections Framework
1
AbstractCollection
Implements most of the Collection interface.
2 AbstractList
3 AbstractSequentialList
Extends AbstractList for use by a collection that uses sequential rather than random
access of its elements.
4 LinkedList
Implements a linked list by extending AbstractSequentialList.
5 ArrayList
Implements a dynamic array by extending AbstractList.
6 AbstractSet
7 HashSet
Extends AbstractSet for use with a hash table.
8 LinkedHashSet
Extends HashSet to allow insertion-order iterations.
9 TreeSet
Implements a set stored in a tree. Extends AbstractSet.
10 AbstractMap
11 HashMap
Extends AbstractMap to use a hash table.
12 TreeMap
https://www.tutorialspoint.com/java/java_collections.htm 3/7
15/04/2022, 16:17 Java - Collections Framework
13 WeakHashMap
Extends AbstractMap to use a hash table with weak keys.
14 LinkedHashMap
Extends HashMap to allow insertion-order iterations.
15 IdentityHashMap
Extends AbstractMap and uses reference equality when comparing documents.
1 Vector
This implements a dynamic array. It is similar to ArrayList, but with some differences.
2 Stack
Stack is a subclass of Vector that implements a standard last-in, first-out stack.
3 Dictionary
Dictionary is an abstract class that represents a key/value storage repository and
operates much like Map.
4 Hashtable
Hashtable was part of the original java.util and is a concrete implementation of a
Dictionary.
5 Properties
Properties is a subclass of Hashtable. It is used to maintain lists of values in which
the key is a String and the value is also a String.
6 BitSet
A BitSet class creates a special type of array that holds bit values. This array can
increase in size as needed.
https://www.tutorialspoint.com/java/java_collections.htm 4/7
15/04/2022, 16:17 Java - Collections Framework
The collections framework defines several algorithms that can be applied to collections and
maps. These algorithms are defined as static methods within the Collections class.
Several of the methods can throw a ClassCastException, which occurs when an attempt is
made to compare incompatible types, or an UnsupportedOperationException, which occurs
when an attempt is made to modify an unmodifiable collection.
Collections define three static variables: EMPTY_SET, EMPTY_LIST, and EMPTY_MAP. All are
immutable.
Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator
extends Iterator to allow bidirectional traversal of a list and the modification of elements.
Both TreeSet and TreeMap store elements in a sorted order. However, it is the comparator that
defines precisely what sorted order means.
This interface lets us sort a given collection any number of different ways. Also this interface can
be used to sort any instances of any class (even classes we cannot modify).
https://www.tutorialspoint.com/java/java_collections.htm 5/7
15/04/2022, 16:17 Java - Collections Framework
Summary
The Java collections framework gives the programmer access to prepackaged data structures
as well as to algorithms for manipulating them.
A collection is an object that can hold references to other objects. The collection interfaces
declare the operations that can be performed on each type of collection.
The classes and interfaces of the collections framework are in package java.util.
16 Lectures 2 hours
Malhar Lathkar
More Detail
Video
19 Lectures 5 hours
Malhar Lathkar
More Detail
Video
https://www.tutorialspoint.com/java/java_collections.htm 6/7
15/04/2022, 16:17 Java - Collections Framework
More Detail
Video
Tushar Kale
More Detail
Video
More Detail
Video
76 Lectures 7 hours
Arnab Chakraborty
More Detail
https://www.tutorialspoint.com/java/java_collections.htm 7/7