0% found this document useful (0 votes)
109 views10 pages

Collection Framework in JAVA

Java colletion framework

Uploaded by

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

Collection Framework in JAVA

Java colletion framework

Uploaded by

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

Topic: Collection Framework

Group members name Roll No.

Akashdeep Naha 11500122070

Barin Ghosh 11500122065

Paramjit Banerjee 11500122086

Avijit Rakshit 11500122064


Collection Framework: Introduction and Application
A Collection represent a group of objects. Java Collection provide classes and interfaces for us to
write code quickly and efficiently. This collections in Java are available as classes and Interfaces. It
is available in java.util package.

Why we need collections?


We need collection for efficient storage and better manipulation of data in java.

Applications:
Organization
The framework provides a standard way to organize and manage data in a flexible and efficient manner.

Reusability
The framework's classes and interfaces are reusable, allowing developers to avoid writing repetitive code.

Performance
The framework is optimized for performance, with efficient algorithms for common operations.
Generics
Generics ensure type safety and prevent runtime errors related to data type mismatches.
Overview of Collection Framework
The Collection Framework provides a hierarchical structure, with different
collection types inheriting from common interfaces .

Collection

The root interface representing a collection of objects.

List

Ordered collection that allows duplicates, providing access by index .

Set

Unordered collection that does not allow duplicates, maintaining


unique elements.
Queue
Queue interface is a subtype of the Collection interface and represents a collection of
elements in a specific order. It follows the first-in, first-out (FIFO) principle.
List Interface
The List interface in Java provides a way to store the ordered collection. It is a child interface of Collection. It is an ordered collection of
objects in which duplicate values can be stored. The implementation classes of the List interface are ArrayList, LinkedList, Stack, and Vector.

List Interface Methods


Method Description

add() Adds an object to a list.

remove() Removes all object from the list.

Clear() Removes all objects from the list.more efficient


than Revove().
Contains() Returns true if a specified object is an element
within the list.
size() Returns the number of elements in the list.

Iterator() sequentially access elements of lists.


Queue Interface
A Queue Interface maintains the FIFO(first in first out) order similar to a real-world queue line. There are
various classes like Priorityqueue, Arraydeque, etc. Once an element is processed then it is removed from
the queue and next item is picked for processing.

Queue Interface Declaration

public interface Queue<E> extends Collection<E>

Queue Interface Methods


Method Description

add() Inserts the specified element into the queue. If the task
is successful, add() returns true.

remove() Returns and removes the head of the queue. Throws an


exception if the queue is empty.

element() Returns the head of the queue. Throws an exception if


the queue is empty.

poll() Returns and removes the head of the queue.


Returns null if the queue is empty

peek() Returns the head of the queue. Returns null if the


queue is empty.
Set Interface
The set interface contains only methods inherited from collection and adds the restriction that duplicate elements
are prohibited. Set has its implementation in various classes like hashset, treeset, linkedhashset.

Set Interface Methods


Method Description

add() Adds an object to the collection.

remove() Removes a specified object from the collection.

Clear() Removes all objects from the collection.

Contains() Returns true if a specified object is an element


within the collection.
size() Returns the number of elements in the collection.

Iterator() The elements from the set are returned in a


random order.
Important Classes From Each Interface
ArrayList PriorityQueue Hashset
The Java ArrayList class provides The Java PriorityQueue class is an The Java HashSet class implements the
resizable-array and implements unbounded priority queue based on a Set interface, backed by a hash
the List interface.Following are the Queue Interfece. table.Following are the important points
important points about ArrayList − about HashSet −
a) The elements of the priority queue a) This class makes no guarantees as
a) It implements all optional list operations are ordered according to their to the iteration order of the set; in
and it also permits all elements, natural ordering, or by a particular, it does not guarantee that
includes null. Comparator provided at queue the order will remain constant over
b) It provides methods to manipulate the construction time, depending on time.
size of the array that is used internally which constructor is used. b) This class permits the null element.
to store the list. b) A priority queue does not permit
null elements.

Method Method
Method
1. boolean add(E e)- appends the specified element 1. boolean add(E e)This method inserts the 1. boolean add(E e)-This method adds the
to the end of this list. specified element to this set if it is not already
specified element into this priority queue.
present
2. boolean addAll(Collection<? extends E> c)- 2. void clear()This method removes all of the 2. void clear()This method removes all of the
This method appends all of the elements in the elements from this priority queue. elements from this set.
specified collection to the end of this list 3. Iterator<E> iterator()This method returns an 3. boolean remove(Object o)-This method
3. void clear()-This method removes all of the removes the specified element from this set if
iterator over the elements in this queue.
it is present.
elements from this list.
Example of Class in Code From Each Interface
Arraylist PriorityQueue Hashset
Advantages and Use Cases & Commonly Used
Collection Classes

Advantages Use Cases Common Classes


The Collection Framework offers type The framework is used to store and ArrayList, LinkedList, HashSet,
safety with generics, improved code manage data in various scenarios, such as HashMap, and TreeSet are widely used in
readability, efficient algorithms, and a shopping carts, user profiles, and Java applications.
standardized approach. configuration settings.
Thank You
Thank you for your time and attention. We hope this presentation
provided you with a good understanding of the Java Collection
Framework.

You might also like