Java Programming Language: Queue Tutorial

Queue

import java.util.PriorityQueue;
PriorityQueue q = new PriorityQueue();

isEmpty()

PriorityQueue q = new PriorityQueue();
System.out.println(q.isEmpty());
Output:
true

add(object)

PriorityQueue q = new PriorityQueue();
q.add(1);
q.add(2);
q.add(3);
System.out.println(q);
System.out.println(q.isEmpty());
Output:
[1, 2, 3]
false

peek()

PriorityQueue q = new PriorityQueue();
q.add(1);
q.add(2);
q.add(3);
System.out.println(q.peek());
Output:
1

remove()

PriorityQueue q = new PriorityQueue();
q.add(1);
q.add(2);
q.add(3);
System.out.println(q);
Output:
[1, 2, 3]
q.remove();
System.out.println(q);
Output:
[2, 3]

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

MarginFi — Uniting Defi Protocols

Front-end web development is not what you think it is.

What I learnt from the GSOC 2021 Application

Rise of No Code Platforms

Powerful filtering for Django Rest Framework

Resurrecting Old Development Workstation — My First Program

The V1 of our dApp is now LIVE!

Git Setup

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jesse L

Jesse L

More from Medium

Object Oriented Programming with Java

Coding Standards in Java

Working with Java Variables

Title image

Coding with Java