- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create Java Priority Queue to ignore duplicates?
The simplest way to create a Java Priority Queue to ignore duplicates is to first create a Set implementation −
HashSet <Integer> set = new HashSet <> (); set.add(100); set.add(150); set.add(250); set.add(300); set.add(250); set.add(500); set.add(600); set.add(500); set.add(900);
Now, create Priority Queue and include the set to remove duplicates in the above set −
PriorityQueue<Integer>queue = new PriorityQueue<>(set);
Example
import java.util.HashSet; import java.util.PriorityQueue; public class Demo { public static void main(String[] args) { HashSet<Integer>set = new HashSet<>(); set.add(100); set.add(150); set.add(250); set.add(300); set.add(250); set.add(500); set.add(600); set.add(500); set.add(900); PriorityQueue<Integer>queue = new PriorityQueue<>(set); System.out.println("Elements with no duplicates = "+queue); } }
Output
Elements with no duplicates = [100, 150, 250, 500, 600, 900, 300]
- Related Articles
- Should we declare it as Queue or Priority Queue while using Priority Queue in Java?
- How to Implement Priority Queue in Python?
- Difference Between Priority Queue and Queue Implementation in Java?
- C++ Program to Implement Priority Queue
- Turn a Queue into Priority Queue
- Meldable Priority Queue Operations
- How to create a Queue from LinkedList in Java?
- Multithreaded Priority Queue in Python
- The Priority Queue in Javascript
- Double Ended Priority Queue (DEPQ)
- How to append data from priority queue to arraylist for listview in Android?
- Creating a Priority Queue using Javascript
- Dequeue and Priority Queue in C++
- Can we use Simple Queue instead of Priority queue to implement Dijkstra’s Algorithm?
- Priority Queue using Linked List in C

Advertisements