SlideShare a Scribd company logo
2
Most read
6
Most read
7
Most read
Java Queue
 The Queue interface present in
the java.util package and extends the Collection
interface is used to hold the elements about to be
processed in FIFO(First In First Out) order. It is an
ordered list of objects with its use limited to insert
elements at the end of the list and deleting
elements from the start of the list, (i.e.), it follows
the FIFO or the First-In-First-Out principle.
Java Queue.pptx
Creating Queue Objects
 Since Queue is an interface, objects cannot be
created of the type queue. We always need a
class which extends this list in order to create an
object. And also, after the introduction
of Generics in Java 1.5, it is possible to restrict
the type of object that can be stored in the
Queue. This type-safe queue can be defined as:
Queue Interface declaration
Method Description
boolean add(object) It is used to insert the specified
element into this queue and return
true upon success.
boolean offer(object) It is used to insert the specified
element into this queue.
Object remove() It is used to retrieves and removes
the head of this queue.
Object poll() It is used to retrieves and removes
the head of this queue, or returns
null if this queue is empty.
Object element() It is used to retrieves, but does not
remove, the head of this queue.
Object peek() It is used to retrieves, but does not
remove, the head of this queue, or
returns null if this queue is empty.
Java PriorityQueue Example
import java.util.*;
class TestCollection12{
public static void main(String args[]){
PriorityQueue<String> queue=new PriorityQueue<String>();
queue.add("Amit");
queue.add("Vijay");
queue.add("Karan");
queue.add("Jai");
queue.add("Rahul");
System.out.println("head:"+queue.element());
System.out.println("head:"+queue.peek());
System.out.println("iterating the queue elements:");
Iterator itr=queue.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
queue.remove();
queue.poll();
System.out.println("after removing two elements:");
Iterator<String> itr2=queue.iterator();
while(itr2.hasNext()){
System.out.println(itr2.next());
}
}
}
Characteristics of a Queue:
 The Queue is used to insert elements at the end of the
queue and removes from the beginning of the queue. It
follows FIFO concept.
 The Java Queue supports all methods of Collection
interface including insertion, deletion etc.
 LinkedList, ArrayBlockingQueue and PriorityQueue are the
most frequently used implementations.
 If any null operation is performed on BlockingQueues,
NullPointerException is thrown.
 The Queues which are available in java.util package are
Unbounded Queues.
 The Queues which are available in java.util.concurrent
package are the Bounded Queues.
 All Queues except the Deques supports insertion and
removal at the tail and head of the queue respectively. The
Deques support element insertion and removal at both
ends.

More Related Content

PPTX
Java Stack Data Structure.pptx
PPT
stack and queue array implementation in java.
PPTX
Java Stack Data Structure.pptx
PDF
Java Serialization
PPT
DS_PPT.ppt
PPTX
Multi-threaded Programming in JAVA
PPT
Queue AS an ADT (Abstract Data Type)
PPTX
Queue and its operations
Java Stack Data Structure.pptx
stack and queue array implementation in java.
Java Stack Data Structure.pptx
Java Serialization
DS_PPT.ppt
Multi-threaded Programming in JAVA
Queue AS an ADT (Abstract Data Type)
Queue and its operations

What's hot (20)

PDF
Java arrays
PPT
Java collections concept
PPTX
Chapter 07 inheritance
PPTX
Constructor in java
PDF
PDF
Polymorphism In Java
PDF
Java Linked List Tutorial | Edureka
PPT
Abstract class in java
PDF
Collections In Java
PPS
String and string buffer
PDF
Arrays in Java
PPTX
JAVA AWT
PPTX
Python: Modules and Packages
PPTX
Polymorphism in java
PPTX
6. static keyword
PPTX
java interface and packages
PPTX
Java exception handling
PPTX
collection framework in java
PPTX
Java program structure
Java arrays
Java collections concept
Chapter 07 inheritance
Constructor in java
Polymorphism In Java
Java Linked List Tutorial | Edureka
Abstract class in java
Collections In Java
String and string buffer
Arrays in Java
JAVA AWT
Python: Modules and Packages
Polymorphism in java
6. static keyword
java interface and packages
Java exception handling
collection framework in java
Java program structure
Ad

Similar to Java Queue.pptx (20)

PPTX
Queue collection of Frame work in oops through java
DOCX
Files to submitProperQueue.javaCreate this file and implement .docx
PPTX
Fundamentals of Data Structure and Queues
PPT
The Queue in Data structure and algorithm
PPT
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
PPT
Queue Data Structure
PPT
Queue Data Structure
PDF
5-Queue-----------------------------in c++
PPTX
Queue types of queue and algorithms and queue
PPT
2 b queues
PPTX
PPTX
GROUP2.pptxfdfffffffffffffffffffffffffffffffffffffffffff
PPT
queueDATA STRUCTURES AND ITS OPERATIONS IMPLEMETED WITH EXAMPLES
PPTX
PPTX
Data Structures and Agorithm: DS 09 Queue.pptx
PDF
A generic queue is a general queue storage that can store an.pdf
PDF
A generic queue is a general queue storage that can store an.pdf
DOCX
EmptyCollectionException-java -- - Represents the situation in which.docx
PDF
Queues-handouts
PPSX
Queue by rajanikanth
Queue collection of Frame work in oops through java
Files to submitProperQueue.javaCreate this file and implement .docx
Fundamentals of Data Structure and Queues
The Queue in Data structure and algorithm
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
Queue Data Structure
Queue Data Structure
5-Queue-----------------------------in c++
Queue types of queue and algorithms and queue
2 b queues
GROUP2.pptxfdfffffffffffffffffffffffffffffffffffffffffff
queueDATA STRUCTURES AND ITS OPERATIONS IMPLEMETED WITH EXAMPLES
Data Structures and Agorithm: DS 09 Queue.pptx
A generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdf
EmptyCollectionException-java -- - Represents the situation in which.docx
Queues-handouts
Queue by rajanikanth
Ad

More from vishal choudhary (20)

PPTX
mobile application using automatin using node ja java on
PPTX
mobile development using node js and java
PPTX
Pixel to Percentage conversion Convert left and right padding of a div to per...
PPTX
esponsive web design means that your website (
PPTX
function in php using like three type of function
PPTX
data base connectivity in php using msql database
PPTX
software evelopment life cycle model and example of water fall model
PPTX
software Engineering lecture on development life cycle
PPTX
strings in php how to use different data types in string
PPTX
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
PPTX
web performnace optimization using css minification
PPTX
web performance optimization using style
PPTX
Data types and variables in php for writing and databse
PPTX
Data types and variables in php for writing
PPTX
Data types and variables in php for writing
PPTX
sofwtare standard for test plan it execution
PPTX
Software test policy and test plan in development
PPTX
function in php like control loop and its uses
PPTX
introduction to php and its uses in daily
PPTX
data type in php and its introduction to use
mobile application using automatin using node ja java on
mobile development using node js and java
Pixel to Percentage conversion Convert left and right padding of a div to per...
esponsive web design means that your website (
function in php using like three type of function
data base connectivity in php using msql database
software evelopment life cycle model and example of water fall model
software Engineering lecture on development life cycle
strings in php how to use different data types in string
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
web performnace optimization using css minification
web performance optimization using style
Data types and variables in php for writing and databse
Data types and variables in php for writing
Data types and variables in php for writing
sofwtare standard for test plan it execution
Software test policy and test plan in development
function in php like control loop and its uses
introduction to php and its uses in daily
data type in php and its introduction to use

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Institutional Correction lecture only . . .
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Pre independence Education in Inndia.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
RMMM.pdf make it easy to upload and study
PDF
01-Introduction-to-Information-Management.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Institutional Correction lecture only . . .
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Pre independence Education in Inndia.pdf
Cell Structure & Organelles in detailed.
RMMM.pdf make it easy to upload and study
01-Introduction-to-Information-Management.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Basic Mud Logging Guide for educational purpose
human mycosis Human fungal infections are called human mycosis..pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
VCE English Exam - Section C Student Revision Booklet
Microbial disease of the cardiovascular and lymphatic systems
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Microbial diseases, their pathogenesis and prophylaxis

Java Queue.pptx

  • 2.  The Queue interface present in the java.util package and extends the Collection interface is used to hold the elements about to be processed in FIFO(First In First Out) order. It is an ordered list of objects with its use limited to insert elements at the end of the list and deleting elements from the start of the list, (i.e.), it follows the FIFO or the First-In-First-Out principle.
  • 4. Creating Queue Objects  Since Queue is an interface, objects cannot be created of the type queue. We always need a class which extends this list in order to create an object. And also, after the introduction of Generics in Java 1.5, it is possible to restrict the type of object that can be stored in the Queue. This type-safe queue can be defined as:
  • 5. Queue Interface declaration Method Description boolean add(object) It is used to insert the specified element into this queue and return true upon success. boolean offer(object) It is used to insert the specified element into this queue. Object remove() It is used to retrieves and removes the head of this queue. Object poll() It is used to retrieves and removes the head of this queue, or returns null if this queue is empty. Object element() It is used to retrieves, but does not remove, the head of this queue. Object peek() It is used to retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
  • 6. Java PriorityQueue Example import java.util.*; class TestCollection12{ public static void main(String args[]){ PriorityQueue<String> queue=new PriorityQueue<String>(); queue.add("Amit"); queue.add("Vijay"); queue.add("Karan"); queue.add("Jai"); queue.add("Rahul"); System.out.println("head:"+queue.element()); System.out.println("head:"+queue.peek()); System.out.println("iterating the queue elements:"); Iterator itr=queue.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); } queue.remove(); queue.poll(); System.out.println("after removing two elements:"); Iterator<String> itr2=queue.iterator(); while(itr2.hasNext()){ System.out.println(itr2.next()); } } }
  • 7. Characteristics of a Queue:  The Queue is used to insert elements at the end of the queue and removes from the beginning of the queue. It follows FIFO concept.  The Java Queue supports all methods of Collection interface including insertion, deletion etc.  LinkedList, ArrayBlockingQueue and PriorityQueue are the most frequently used implementations.  If any null operation is performed on BlockingQueues, NullPointerException is thrown.  The Queues which are available in java.util package are Unbounded Queues.  The Queues which are available in java.util.concurrent package are the Bounded Queues.  All Queues except the Deques supports insertion and removal at the tail and head of the queue respectively. The Deques support element insertion and removal at both ends.