0% found this document useful (0 votes)
9 views

Class GJRN

Uploaded by

pkt6279
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Class GJRN

Uploaded by

pkt6279
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Java Collection Framework Overview

Collection Framework in Java

The Java Collection Framework provides a set of classes and interfaces that implement commonly

reusable collection data structures. Collections are used to store, retrieve, manipulate, and

communicate aggregate data.

Hierarchy of Collection Framework

The main interfaces in the Collection framework are:

1. Collection Interface: The root of the collection hierarchy.

- List Interface: Ordered collection (sequence). Allows duplicate elements.

- ArrayList Class

- LinkedList Class

- Vector Class

- Stack Class

- Set Interface: A collection that does not allow duplicate elements.

- HashSet Class

- LinkedHashSet Class

- SortedSet Interface

- TreeSet Class

- Queue Interface: A collection used to hold multiple elements prior to processing.

- PriorityQueue Class

- Deque Interface
Java Collection Framework Overview

- ArrayDeque Class

2. Map Interface: An object that maps keys to values.

- HashMap Class

- LinkedHashMap Class

- SortedMap Interface

- TreeMap Class

- Hashtable Class

Iterator Interface

The Iterator interface provides methods to iterate over any Collection. It has three main methods:

- boolean hasNext(): Returns true if there are more elements to iterate.

- E next(): Returns the next element in the iteration.

- void remove(): Removes the last element returned by the iterator.

Set Interface

The Set interface extends the Collection interface and represents a collection that does not contain

duplicate elements. It has the following implementations:

- HashSet

- LinkedHashSet

- TreeSet
Java Collection Framework Overview

HashSet

HashSet is an implementation of the Set interface backed by a hash table. It does not guarantee

any specific order of elements.

- HashSet allows null elements.

- It provides constant-time performance for basic operations like add, remove, contains, and size.

LinkedHashSet

LinkedHashSet is a subclass of HashSet and implements the Set interface. It maintains a linked list

of the entries in the set, in the order in which they were inserted.

- It provides insertion-order iteration.

SortedSet Interface

The SortedSet interface extends the Set interface and provides a total ordering on its elements.

- TreeSet is the only implementation of the SortedSet interface.

TreeSet

TreeSet is an implementation of the NavigableSet interface, a subtype of SortedSet. It uses a

Red-Black tree structure to store elements.

- It guarantees that the elements will be in ascending order, according to their natural order or by a
Java Collection Framework Overview

specified comparator.

- TreeSet does not allow null elements.

Map Interface

The Map interface maps unique keys to values. A map cannot contain duplicate keys, and each key

can map to at most one value.

- HashMap

- LinkedHashMap

- TreeMap

- Hashtable

HashMap Class

HashMap is an implementation of the Map interface backed by a hash table. It allows null values

and the null key.

- It provides constant-time performance for basic operations like get and put.

LinkedHashMap Class

LinkedHashMap extends HashMap and maintains a doubly-linked list running through all of its

entries. This linked list defines the iteration ordering, which is normally the order in which keys were

inserted into the map.

- It allows insertion-order iteration.


Java Collection Framework Overview

TreeMap Class

TreeMap is an implementation of the NavigableMap interface, which extends SortedMap. It is based

on a Red-Black tree.

- It orders its keys based on their natural ordering or by a specified comparator.

- TreeMap does not allow null keys.

Hashtable Class

Hashtable is a legacy class that implements the Map interface. It is synchronized and does not allow

null keys or values.

- It is generally considered obsolete in favor of the more modern HashMap class, unless thread-safe

behavior is required.

You might also like