PriorityQueue class clear()method example
Removes all of the elements from this priority queue.
PriorityQueue class clear()method example. This example shows you how to use clear()method.This method Removes all of the elements from this priority queue.
Here is the code:-
/**
* @Program that Removes all of the elements from this priority queue.
* Clear.java
* Author:-RoseIndia Team
* Date:-28-May-2008
*/
import java.util.*;
public class Clear {
public static void main(String[] args) {
PriorityQueue p = new PriorityQueue();
//Inserts the specified element into this priority queue.
p.add("Girish");
p.add("Tewari");
System.out.println("Elements in the PriorityQueue are: " + p);
//Removes all of the elements from this priority queue.
p.clear();
System.out.println("Elements in the PriorityQueue are: " + p);
}
} |
Output of the program:-
Elements in the PriorityQueue are: [Girish, Tewari]
Elements in the PriorityQueue are: [] |
|