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

Java Complete Collection Framework

This document discusses Java collection classes. It explains that collections allow storing and manipulating groups of objects and describes common collection classes like ArrayList, LinkedList, Vector, Stack, Queue, PriorityQueue, HashSet, LinkedHashSet, and TreeSet. It provides code snippets and discusses the characteristics of each class, such as how they store elements, whether they allow duplicates, and whether they are synchronized.

Uploaded by

khushivansh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views

Java Complete Collection Framework

This document discusses Java collection classes. It explains that collections allow storing and manipulating groups of objects and describes common collection classes like ArrayList, LinkedList, Vector, Stack, Queue, PriorityQueue, HashSet, LinkedHashSet, and TreeSet. It provides code snippets and discusses the characteristics of each class, such as how they store elements, whether they allow duplicates, and whether they are synchronized.

Uploaded by

khushivansh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

linkedin.

com/in/soumyadip-chowdhury/

youtube.com/println

@s_oumyadip
INTRODUCTION
Java's Collection
framework provides a way to store
and manipulate groups of objects. Java Collections can
be used for searching, sorting, inserting, manipulating,
and deleting data.

In Java, a collection is a single unit of objects.


ArrayList, Vector, LinkedList, PriorityQueue, HashSet,
LinkedHashSet, TreeSet, and LinkedList are all classes
of Java Collection framework.

/soumyadip-chowdhury
Hierarchy of Collection
Framework

/soumyadip-chowdhury
List Interface
The List interface is a child interface of the Collection
interface. We cannot store an ordered collection of
objects in a list-type data structure. Values can be
duplicated.

Arraylist
The list is implemented by the ArrayList class. It uses a
dynamic array to store the duplicate element of
different data types.

The ArrayList class maintains the insertion order and


is non-synchronized. The elements stored in the
ArrayList class can be randomly accessed.

/soumyadip-chowdhury
ARRAYLIST Snippet

/soumyadip-chowdhury
LinkedList
The LinkedList class implements the Collection
interface. Internally, the elements are stored in a
doubly linked list. Duplicate elements can be stored.

There is no synchronization and i maintains the order


of insertion. In LinkedList, the manipulation is fast
because no shifting is required.

/soumyadip-chowdhury
LinkedList Snippet
Vector

Vector stores the data elements in a dynamic


array. It resembles an array list.

It is synchronized, though, and has a lot of


methods that are not included in the Collection
framework.

/soumyadip-chowdhury
Vector Snippet

/soumyadip-chowdhury
Stack
A subtype of the vector is the stack. It uses the
stack data structure, or last-in, first-out.

The stack offers the methods of the Vector class,


including boolean push(), boolean peek(), and
boolean push(object o), which specify the class's
properties.

/soumyadip-chowdhury
Stack Snippet
Queue
The order of first-in, first-out is maintained through
the queue interface. It can be characterized as an
ordered list used to store pieces that are scheduled to
undergo processing.

There are many classes that implement the Queue


interface, including PriorityQueue, Deque, and
ArrayDeque.

/soumyadip-chowdhury
Queue Snippet

/soumyadip-chowdhury
PriorityQueue

The Queue interface is implemented by the


PriorityQueue class.

It contains the substances or things that must be


handled according to their priority. Null values
cannot be saved in the queue using
PriorityQueue.

/soumyadip-chowdhury
Priority Queue Snippet

/soumyadip-chowdhury
Deque Interface

The Queue interface is expanded by the Deque


interface. In Deque, we have the ability to
remove and add parts from either side.

A double-ended queue known by the


abbreviation DEQUE allows us to conduct
operations at both ends.

/soumyadip-chowdhury
ArrayDeque

ArrayDeque class implements the Deque


interface. It facilitates us to use the Deque.
Unlike queue, we can add or delete the elements
from both ends.

ArrayDeque is faster than ArrayList and Stack


and has no capacity restrictions.

/soumyadip-chowdhury
ArrayDeque Snippet

/soumyadip-chowdhury
Set Interface

The Java.util package contains the Set Interface. The


Collection interface is expanded by it.

It stands for an unordered set of elements that


prevents us from storing duplicate stuff. In Set, there
can only be one null value stored.

HashSet, LinkedHashSet, and TreeSet all implement


Set.

/soumyadip-chowdhury
Set Snippet

/soumyadip-chowdhury
HashSet

Set Interface is implemented by HashSet class. It


stands for the collection that stores data using
hash tables.

The components of the HashSet are stored using


hashing. It has special stuff in it.

/soumyadip-chowdhury
Set Snippet

/soumyadip-chowdhury
LinkedHashSet

The LinkedList implementation of the Set


Interface is represented by the LinkedHashSet
class.

It implements the Set interface and extends the


HashSet class. It has distinctive components just
like HashSet. It permits null elements and
preserves insertion order.

/soumyadip-chowdhury
LinkedHashSet Snippet
SortedSet Interface

The alternative to the Set interface,


known as
SortedSet, offers a complete ordering of its
items.

The SortedSet's elements are organized in


ascending (increasing) order. The SortedSet
offers extra methods that prevent the elements'
default sorting.

/soumyadip-chowdhury
TreeSet Interface

which uses a tree for storage,
The Set interface,
is implemented by the Java TreeSet class.

TreeSet has distinct components, just as


HashSet. However, TreeSet has fairly quick
access and retrieval time. The TreeSet stores its
elements in ascending order.

/soumyadip-chowdhury
TreeSet Snippet

/soumyadip-chowdhury
And for amazing stuff you can follow me

Soumyadip Chowdhury
soumyadip-chowdhury
@s_oumyadip
@println

References:

https://www.javatpoint.com/collections-in-java

You might also like