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

Module 9 Collections

This document provides an overview of the Java Collections framework, detailing its architecture for storing and manipulating groups of objects. It covers various interfaces and classes, including Collection, List, Set, Queue, and their implementations like ArrayList, HashSet, and PriorityQueue. Additionally, it explains the advantages of using generic collections and the methods associated with each interface.

Uploaded by

nemesis22aov
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)
4 views

Module 9 Collections

This document provides an overview of the Java Collections framework, detailing its architecture for storing and manipulating groups of objects. It covers various interfaces and classes, including Collection, List, Set, Queue, and their implementations like ArrayList, HashSet, and PriorityQueue. Additionally, it explains the advantages of using generic collections and the methods associated with each interface.

Uploaded by

nemesis22aov
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/ 28

Object Oriented Programming

(Java)
Module 9
Collections
Learn how to manipulate and manage data
Understand when and where to use different collection
types
Understand and define the advantage of Generic
Collection

Familiarize with the Java Collections class methods


Apply different collection type based on their structure
of ordering and uniqueness
Collections Part 1

9.1

Collections
Collection

ØThe Collection in Java is a framework that provides an architecture to store and manipulate the
group of objects.

Ø Java Collections can achieve all the operations that you perform on a data such as searching,
sorting, insertion, manipulation, and deletion.

Ø Java Collection means a single unit of objects. Java Collection framework provides many
interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue,
HashSet, LinkedHashSet, TreeSet).

Collections
Collection

Ø What is Collection in Java


Ø A Collection represents a single unit of objects, i.e., a group.
Ø What is a framework in Java
Ø It provides readymade architecture.
Ø It represents a set of classes and interfaces.
Ø It is optional.
Ø What is Collection framework
Ø The Collection framework represents a unified architecture for storing and manipulating a group
of objects. It has:
Ø Interfaces and its implementations, i.e., classes
Ø Algorithm

Collections
Hierarchy of Collection Framework

ØThe java.util package contains all the classes and interfaces for the Collection framework.

Collections
Methods of Collection interface

• Collection 8
Methods of Collection interface

Collections
Iterable Interface

Ø The Iterable interface is the root interface for all the collection classes. The Collection interface
extends the Iterable interface and therefore all the subclasses of Collection interface also implement
the Iterable interface.

Ø It contains only one abstract method. i.e.,

Collections
Collection Interface

Ø The Collection interface is the interface which is implemented by all the classes in the collection
framework. It declares the methods that every collection will have. In other words, we can say that
the Collection interface builds the foundation on which the collection framework depends.

Ø Some of the methods of Collection interface are Boolean add ( Object obj), Boolean addAll (
Collection c), void clear(), etc. which are implemented by all the subclasses of Collection interface.

Collections
List Interface

Ø List interface is the child interface of Collection interface. It inhibits a list type data structure in
which we can store the ordered collection of objects. It can have duplicate values.
Ø List interface is implemented by the classes ArrayList, LinkedList, Vector, and Stack.
Ø To instantiate the List interface, we must use :

Ø There are various methods in List interface that can be used to insert, delete, and access the
elements from the list.

Collections
ArrayList

Ø The ArrayList class implements the List


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

Collections
LinkedList

Ø LinkedList implements the Collection


interface. It uses a doubly linked list internally
to store the elements. It can store the duplicate
elements. It maintains the insertion order and is
not synchronized. In LinkedList, the
manipulation is fast because no shifting is
required.

Collections
Vector

Ø Vector uses a dynamic array to store the


data elements. It is similar to ArrayList.
However, It is synchronized and contains
many methods that are not the part of
Collection framework.

Collections
Stack

Ø The stack is the subclass of Vector. It implements the


last-in-first-out data structure, i.e., Stack. The stack
contains all of the methods of Vector class and also
provides its methods like boolean push(), boolean
peek(), boolean push(object o), which defines its
properties.

Collections
Collections Part 2

9.1

Collections
Queue Interface

Ø Queue interface maintains the first-in-first-out order. It can be defined as an ordered list that is
used to hold the elements which are about to be processed. There are various classes like
PriorityQueue, Deque, and ArrayDeque which implements the Queue interface.

Ø Queue interface can be instantiated as:

Collections
PriorityQueue

Ø The PriorityQueue class implements


the Queue interface. It holds the
elements or objects which are to be
processed by their priorities.
PriorityQueue doesn't allow null values
to be stored in the queue.

Collections 19
Deque Interface

Ø Deque interface extends the Queue interface. In Deque, we can remove and add the
elements from both the side. Deque stands for a double-ended queue which enables us to
perform the operations at both the ends.
Ø Deque can be instantiated as:

Collections
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 the ends.
ArrayDeque is faster than ArrayList and Stack
and has no capacity restrictions.

Collections
Set Interface

Ø Set Interface in Java is present in java.util package. It extends the Collection interface. It
represents the unordered set of elements which doesn't allow us to store the duplicate items. We
can store at most one null value in Set. Set is implemented by HashSet, LinkedHashSet, and
TreeSet.

Ø Set can be instantiated as:

Collections
Hashset

Ø HashSet class implements Set Interface. It


represents the collection that uses a hash
table for storage. Hashing is used to store the
elements in the HashSet. It contains unique
items.

Collections
Linked Hashset

Ø LinkedHashSet class represents the


LinkedList implementation of Set Interface. It
extends the HashSet class and implements
Set interface. Like HashSet, It also contains
unique elements. It maintains the insertion
order and permits null elements.

Collections
SortedSet Interface

Ø SortedSet is the alternate of Set interface that provides a total ordering on its elements. The
elements of the SortedSet are arranged in the increasing (ascending) order. The SortedSet
provides the additional methods that inhibit the natural ordering of the elements.

Ø The SortedSet can be instantiated as:

Collections
TreeSet

Ø Java TreeSet class implements the Set


interface that uses a tree for storage. Like
HashSet, TreeSet also contains unique
elements. However, the access and retrieval
time of TreeSet is quite fast. The elements in
TreeSet stored in ascending order.

Collections
Backiel, A. (2015). Beginning Java Programming: The Object-oriented Approach. 1st Edition
Fain, Y. (2015). Java programming 24-hour trainer. John Wiley and Sons:Indianapolis, IN
Smith, J. (2015). Java programs to accompany Programming logic and design. Cengage Learning:Boston, MA
Yener, M (2015). Professional Java EE Design Patterns. John Wiley & Sons, Inc.
Gordon, S. (2017). Computer Graphics Programming in opengl with Java. Mercury Learning and Information
Butler, A (2017). Java. s.n
Lowe, D (2017). Java all-in-one for dummies. John Wiley and Sons
Saumont, P (2017). Functional Programming in Java: How Functional Techniques Improve Your Java Programs. 1st Edition
Heffelfinger, D. (2017). Java EE 8 Application Development. Packt Puublishing
Murach, J. (2017). Murach’s Java Programming. Mike Murach & Associates,Inc.
Burd, B. (2017). Beginning programming with Java for dummies. John Wiley & Sons, Inc.
Manelli, L. (2017). Developing java web application in a day. s.n.
Klausen, P. (2017). Java 5: Files and Java IO software development (e-book)
Klausen, P. (2017). Java 3 object-oriented programming software development (e-book)
Muller, M (2018). Practical JSF in Java EE 8. Apress

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy