PriorityQueue class remove(Object o)method example

Removes a single instance of the specified element from this queue


PriorityQueue class remove(Object o)method example. This example shows you how to use remove(Object o) method.This method Removes a single instance of the specified element from this queue, if it is present.

Here is the code:-

/**
 * @Program that  Removes a single instance of the specified element from this
 * queue, if it is present.
 * Remove.java 
 * Author:-RoseIndia Team
 * Date:-28-May-2008
 */
import java.util.*;

public class Remove {

    public static void main(String[] args) {
//Creating a  PriorityQueue   
        PriorityQueue p = new PriorityQueue();
//Adding element to the queue
        p.add("1");
        p.add("2");
        p.add("3");
        p.add("4");
        p.add("5");
        p.add("6");
//creating an iterator interface
        Iterator i = p.iterator();
        System.out.print("Elements of the Queue  before Removing are: ");
        while (i.hasNext()) {
            System.out.print(i.next() "\t");
        }
// Removes a single instance of the specified element from this queue,
        p.remove("3");
        Iterator i1 = p.iterator();
        System.out.println();
        System.out.print("Elements of the Queue after Removing are: ");
        while (i1.hasNext()) {
            System.out.print(i1.next() "\t");
        }

    }
}

Output of the program:-
Elements of the Queue  before Removing are: 1    2    3    4    5    6   
Elements of the Queue after Removing are: 1    2    6    4    5

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US