Java PriorityBlockingQueue removeAll() Method Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Java, the removeAll() method of the PriorityBlockingQueue class is used to remove all elements from the queue that are also present in another specified collection. Example 1: The below Java program demonstrates the use of the removeAll() method to remove all the elements of integer type from a PriorityBlockingQueue. Java // Use of removeAll() in PriorityBlockingQueue // of Integer type import java.util.Arrays; import java.util.concurrent.PriorityBlockingQueue; import java.util.function.Predicate; class Geeks { public static void main(String[] args) { // Creating a PriorityBlockingQueue of integers PriorityBlockingQueue<Integer> q = new PriorityBlockingQueue<>(); // Use add() to insert elements in the queue q.add(10); q.add(20); q.add(30); q.add(40); q.add(50); // Display the original PriorityBlockingQueue System.out.println( "Original PriorityBlockingQueue: " + q); // Creating a list of elements // to remove from the queue PriorityBlockingQueue<Integer> r = new PriorityBlockingQueue<>( Arrays.asList(30, 50)); // Remove all elements that are in the r collection q.removeAll(r); // Display the PriorityBlockingQueue after removal System.out.println("PriorityBlockingQueue after removeAll(): " + q); } } OutputOriginal PriorityBlockingQueue: [10, 20, 30, 40, 50] PriorityBlockingQueue after removeAll(): [10, 20, 40] Syntax of PriorityBlockingQueue removeAll() Methodboolean removeAll(Collection c)Parameter: The collection "c" is the collection of elements to be removed from the queue.Return type: It returns true, if the elements were successfully removed. It returns false, if no elements were removed.Example 2: Here, we will demonstrate the use of the removeAll() method to remove specific string elements from a PriorityBlockingQueue. Java // Use of removeAll() in PriorityBlockingQueue // of String type import java.util.concurrent.PriorityBlockingQueue; public class Geeks { public static void main(String[] args) { // Creating a PriorityBlockingQueue of strings PriorityBlockingQueue<String> q = new PriorityBlockingQueue<>(); // Adding elements to the queue q.add("A"); q.add("B"); q.add("C"); q.add("D"); q.add("E"); // Display the original PriorityBlockingQueue System.out.println("Original PriorityBlockingQueue: " + q); // Creating a collection of elements to remove PriorityBlockingQueue<String> r = new PriorityBlockingQueue<>(); r.add("B"); r.add("D"); // Removing elements from the queue q.removeAll(r); // Display the modified PriorityBlockingQueue System.out.println("PriorityBlockingQueue after removeAll(): " + q); } } OutputOriginal PriorityBlockingQueue: [A, B, C, D, E] PriorityBlockingQueue after removeAll(): [A, C, E] Comment More infoAdvertise with us Next Article Must Coding Questions - Company-wise J juhisrivastav Follow Improve Article Tags : Java Java-PriorityBlockingQueue Practice Tags : Java Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like