SlideShare a Scribd company logo
LAB #7
Prepared by: Berk Soysal
2016 Winter
ArrayQueueLinkedListVectorArrayList
Java comes with a group of generic collection classes that grow as more
elements are added to them. This group of collection classes are referred to
as the Java Collections Framework.
2016 Winter
โ€ข The Set interface defines the methods required to process a
collection of objects in which there is no repetition, and
ordering is unimportant.
โ€ข Which of these are sets?
โ€“ a queue of people waiting to see a doctor;
โ€“ a list of number one records for each of the 52 weeks of a particular
year;
โ€“ car registration numbers allocated parking permits.
โ€ข There are three implementations provided for the Set
interface in the JCF ( Java Collections Framework).
โ€ข They are HashSet, LinkedHashSet and TreeSet.
โ€ข Only the collection of car registration numbers can be
considered a set as there will be no duplicates and ordering
is unimportant.
2016 Winter
ArrayList LinkedList
1) ArrayList internally uses dynamic
array to store the elements.
LinkedList internally uses doubly
linked list to store the elements.
2) Manipulation with ArrayList is
slow because it internally uses
arrays. If any element is removed
from the array, all the bits are
shifted in memory.
Manipulation with LinkedList is
faster than ArrayList because it uses
doubly linked list so no bit shifting is
required in memory.
3) ArrayList class can act as a list
only because it implements List only.
LinkedList class can act as a list and
queue both because it implements
List and Deque interfaces.
4) ArrayList is better for storing and
accessing data(reading).
LinkedList is better for manipulating
data.
2016 Winter
โ€ข The List interface specifies the methods required to process an
ordered list of objects.
โ€ข Such a list may contain duplicates.
Examples of a list of objects:
โ€ข Jobs waiting for a printer,
โ€ข Emergency calls waiting for an ambulance
โ€ข The names of players that have won the Wimbledon tennis
tournament over the last 10 years.
โ€ข We often think of such a collection as a sequence of objects.
โ€ข There are three implementations provided for the List interface
in the JCF.
โ€ข They are ArrayList, Vector (Not preferred) and LinkedList.
2016 Winter
โ€ข Queue: Retrieves elements in the order they were added.
โ€ข First-In, First-Out ("FIFO")
โ€ข Elements are stored in order of
insertion but don't have indexes.
โ€ข Client can only add to the end of the
queue, and can only examine/remove
the front of the queue.
โ€ข Basic queue operations:
โ€“ add (enqueue): Add an element to the back.
โ€“ remove (dequeue): Remove the front element.
โ€“ peek: Examine the front element.
2016 Winter
โ€ข Just like Stacks, Queues can be implemented by using two
families of implementations:
๏ƒ˜ Array-based implementation
๏ƒ˜ LinkedList-based implementation
2016 Winter
โ€ข The first implementation stores the underlying collection in a
fixed-sized array.
2016 Winter
โ€ข The second implementation uses a linked-list to store the
queueโ€™s contents. Using such an approach provides a very
efficient, succinct implementation with low computation
complexity.
2016 Winter
โ€ข Each element (node) of a list comprises of two items - the
data and a reference to the next node.
โ€ข The last node has a reference to null.
โ€ข The entry point into a linked list is called the head of the list.
It should be noted that head is not a separate node, but the
reference to the first node. If the list is empty then the head
is a null reference.
Figure - Singly Linked List
2016 Winter
โ€ข A doubly linked list is a list that has two references, one to
the next node and another to previous node.
Figure โ€“ A Doubly Linked List
โ€ข Another important type of a linked list is called a circular linked list
where last node of the list points back to the first node (or the head)
of the list.
2016 Winter
For this laboratory, we are developing a computer simulation
for a supermarket that has express and regular lines. These
waiting lines will be implemented with help of queues.
2016 Winter
As you can see, the average waiting time for the
express line was short (16 seconds!) but the
customers in the regular line are waiting more than
30 minutes. The manager needs to add regular lines.
But how many lines should be added? To answer this
question, you will need to modify this application to
allow for more regular lines;
2016 Winter
2016 Winter
Please take a look at the code provided in the folder;
Lab7 -> Queue Implementations -> LinkedList Queues ->โ€ฆ
2016 Winter
2016 Winter

More Related Content

What's hot (20)

ODP
Knolx Session: Introducing Extractors in Scala
Ayush Mishra
ย 
PPTX
Intro++ to C#
Pixelles / Rebecca Cohen-Palacios
ย 
PDF
Introducing Pattern Matching in Scala
Ayush Mishra
ย 
PPTX
Net framework
Abhishek Mukherjee
ย 
ODP
Knolx Session : Built-In Control Structures in Scala
Ayush Mishra
ย 
PPTX
Python programming
sirikeshava
ย 
PPTX
30csharp
Sireesh K
ย 
PDF
Simplicitly
Martin Odersky
ย 
PPTX
32sql server
Sireesh K
ย 
PPTX
Adobe Flash Actionscript language basics chapter-2
Nafis Ahmed
ย 
PPTX
2CPP13 - Operator Overloading
Michael Heron
ย 
PPTX
Java 103 intro to java data structures
agorolabs
ย 
PDF
What To Leave Implicit
Martin Odersky
ย 
PPT
2CPP16 - STL
Michael Heron
ย 
PDF
STL in C++
Surya Prakash Sahu
ย 
PPTX
Understanding the components of standard template library
Rahul Sharma
ย 
PPT
standard template library(STL) in C++
โ€ขsreejith โ€ขsree
ย 
PPTX
What To Leave Implicit
Martin Odersky
ย 
PPTX
Java Programming
Nanthini Kempaiyan
ย 
PDF
Introduction on Data Structures
Nanthini Kempaiyan
ย 
Knolx Session: Introducing Extractors in Scala
Ayush Mishra
ย 
Introducing Pattern Matching in Scala
Ayush Mishra
ย 
Net framework
Abhishek Mukherjee
ย 
Knolx Session : Built-In Control Structures in Scala
Ayush Mishra
ย 
Python programming
sirikeshava
ย 
30csharp
Sireesh K
ย 
Simplicitly
Martin Odersky
ย 
32sql server
Sireesh K
ย 
Adobe Flash Actionscript language basics chapter-2
Nafis Ahmed
ย 
2CPP13 - Operator Overloading
Michael Heron
ย 
Java 103 intro to java data structures
agorolabs
ย 
What To Leave Implicit
Martin Odersky
ย 
2CPP16 - STL
Michael Heron
ย 
STL in C++
Surya Prakash Sahu
ย 
Understanding the components of standard template library
Rahul Sharma
ย 
standard template library(STL) in C++
โ€ขsreejith โ€ขsree
ย 
What To Leave Implicit
Martin Odersky
ย 
Java Programming
Nanthini Kempaiyan
ย 
Introduction on Data Structures
Nanthini Kempaiyan
ย 

Similar to Java Tutorial Lab 7 (20)

PPTX
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
ย 
PPTX
Bca ii dfs u-2 linklist,stack,queue
Rai University
ย 
PPTX
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
logesswarisrinivasan
ย 
PPTX
Mca ii dfs u-3 linklist,stack,queue
Rai University
ย 
PPT
11000121065_NAITIK CHATTERJEE.ppt
NaitikChatterjee
ย 
PPTX
Queue collection of Frame work in oops through java
bhavanibhanu3456
ย 
PDF
Lec3
Nikhil Chilwant
ย 
PPTX
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
ย 
PPT
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
ย 
PPTX
Introduction in Data Structure - stack, Queue
BharathiKrishna6
ย 
PPTX
Data Structures(Part 1)
Dr. SURBHI SAROHA
ย 
PDF
Queue ADT for data structure for computer
abinathsabi
ย 
PPT
Lec3
Anjneya Varshney
ย 
PDF
07 java collection
Abhishek Khune
ย 
PPTX
LinkedList vs Arraylist- an in depth look at java.util.LinkedList
Marcus Biel
ย 
PPTX
STACKS AND QUEUES CONCEPTS
Malikireddy Bramhananda Reddy
ย 
PPTX
Collections framework in java
yugandhar vadlamudi
ย 
PPT
Stacks, Queues, Deques
A-Tech and Software Development
ย 
PPTX
Data Structures and Agorithm: DS 09 Queue.pptx
RashidFaridChishti
ย 
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
ย 
Bca ii dfs u-2 linklist,stack,queue
Rai University
ย 
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
logesswarisrinivasan
ย 
Mca ii dfs u-3 linklist,stack,queue
Rai University
ย 
11000121065_NAITIK CHATTERJEE.ppt
NaitikChatterjee
ย 
Queue collection of Frame work in oops through java
bhavanibhanu3456
ย 
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
ย 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
ย 
Introduction in Data Structure - stack, Queue
BharathiKrishna6
ย 
Data Structures(Part 1)
Dr. SURBHI SAROHA
ย 
Queue ADT for data structure for computer
abinathsabi
ย 
07 java collection
Abhishek Khune
ย 
LinkedList vs Arraylist- an in depth look at java.util.LinkedList
Marcus Biel
ย 
STACKS AND QUEUES CONCEPTS
Malikireddy Bramhananda Reddy
ย 
Collections framework in java
yugandhar vadlamudi
ย 
Stacks, Queues, Deques
A-Tech and Software Development
ย 
Data Structures and Agorithm: DS 09 Queue.pptx
RashidFaridChishti
ย 
Ad

Recently uploaded (20)

PPTX
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
ย 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
ย 
PDF
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
ย 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
ย 
PPTX
For my supp to finally picking supp that work
necas19388
ย 
PPTX
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
ย 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
ย 
PPTX
declaration of Variables and constants.pptx
meemee7378
ย 
PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
ย 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
ย 
PDF
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
PDF
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
ย 
PDF
Code Once; Run Everywhere - A Beginnerโ€™s Journey with React Native
Hasitha Walpola
ย 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
PPTX
Introduction to web development | MERN Stack
JosephLiyon
ย 
PDF
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
ย 
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
ย 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
ย 
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
ย 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
ย 
For my supp to finally picking supp that work
necas19388
ย 
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
ย 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
ย 
declaration of Variables and constants.pptx
meemee7378
ย 
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
ย 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
ย 
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
ย 
Code Once; Run Everywhere - A Beginnerโ€™s Journey with React Native
Hasitha Walpola
ย 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
Introduction to web development | MERN Stack
JosephLiyon
ย 
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
ย 
Ad

Java Tutorial Lab 7

  • 1. LAB #7 Prepared by: Berk Soysal 2016 Winter
  • 2. ArrayQueueLinkedListVectorArrayList Java comes with a group of generic collection classes that grow as more elements are added to them. This group of collection classes are referred to as the Java Collections Framework. 2016 Winter
  • 3. โ€ข The Set interface defines the methods required to process a collection of objects in which there is no repetition, and ordering is unimportant. โ€ข Which of these are sets? โ€“ a queue of people waiting to see a doctor; โ€“ a list of number one records for each of the 52 weeks of a particular year; โ€“ car registration numbers allocated parking permits. โ€ข There are three implementations provided for the Set interface in the JCF ( Java Collections Framework). โ€ข They are HashSet, LinkedHashSet and TreeSet. โ€ข Only the collection of car registration numbers can be considered a set as there will be no duplicates and ordering is unimportant. 2016 Winter
  • 4. ArrayList LinkedList 1) ArrayList internally uses dynamic array to store the elements. LinkedList internally uses doubly linked list to store the elements. 2) Manipulation with ArrayList is slow because it internally uses arrays. If any element is removed from the array, all the bits are shifted in memory. Manipulation with LinkedList is faster than ArrayList because it uses doubly linked list so no bit shifting is required in memory. 3) ArrayList class can act as a list only because it implements List only. LinkedList class can act as a list and queue both because it implements List and Deque interfaces. 4) ArrayList is better for storing and accessing data(reading). LinkedList is better for manipulating data. 2016 Winter
  • 5. โ€ข The List interface specifies the methods required to process an ordered list of objects. โ€ข Such a list may contain duplicates. Examples of a list of objects: โ€ข Jobs waiting for a printer, โ€ข Emergency calls waiting for an ambulance โ€ข The names of players that have won the Wimbledon tennis tournament over the last 10 years. โ€ข We often think of such a collection as a sequence of objects. โ€ข There are three implementations provided for the List interface in the JCF. โ€ข They are ArrayList, Vector (Not preferred) and LinkedList. 2016 Winter
  • 6. โ€ข Queue: Retrieves elements in the order they were added. โ€ข First-In, First-Out ("FIFO") โ€ข Elements are stored in order of insertion but don't have indexes. โ€ข Client can only add to the end of the queue, and can only examine/remove the front of the queue. โ€ข Basic queue operations: โ€“ add (enqueue): Add an element to the back. โ€“ remove (dequeue): Remove the front element. โ€“ peek: Examine the front element. 2016 Winter
  • 7. โ€ข Just like Stacks, Queues can be implemented by using two families of implementations: ๏ƒ˜ Array-based implementation ๏ƒ˜ LinkedList-based implementation 2016 Winter
  • 8. โ€ข The first implementation stores the underlying collection in a fixed-sized array. 2016 Winter
  • 9. โ€ข The second implementation uses a linked-list to store the queueโ€™s contents. Using such an approach provides a very efficient, succinct implementation with low computation complexity. 2016 Winter
  • 10. โ€ข Each element (node) of a list comprises of two items - the data and a reference to the next node. โ€ข The last node has a reference to null. โ€ข The entry point into a linked list is called the head of the list. It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference. Figure - Singly Linked List 2016 Winter
  • 11. โ€ข A doubly linked list is a list that has two references, one to the next node and another to previous node. Figure โ€“ A Doubly Linked List โ€ข Another important type of a linked list is called a circular linked list where last node of the list points back to the first node (or the head) of the list. 2016 Winter
  • 12. For this laboratory, we are developing a computer simulation for a supermarket that has express and regular lines. These waiting lines will be implemented with help of queues. 2016 Winter
  • 13. As you can see, the average waiting time for the express line was short (16 seconds!) but the customers in the regular line are waiting more than 30 minutes. The manager needs to add regular lines. But how many lines should be added? To answer this question, you will need to modify this application to allow for more regular lines; 2016 Winter
  • 15. Please take a look at the code provided in the folder; Lab7 -> Queue Implementations -> LinkedList Queues ->โ€ฆ 2016 Winter