PriorityQueue class offer(E e)method example

Inserts the specified element into this priority queue.


PriorityQueue class offer(E e)method example. This example shows you how to use offer(E e)method.This method Inserts the specified element into this priority queue.

Here is the code:-

/**
 * @Program that Inserts the specified element into this priority queue.
 * Offer.java 
 * Author:-RoseIndia Team
 * Date:-28-May-2008
 */
import java.util.*;

public class Offer {

    public static void main(String[] args) {
//Creating a  PriorityQueue   
        PriorityQueue p = new PriorityQueue();
//Adding element to the queue
        p.add("Girish");
        p.add("Tewari");
        p.add("A");
        p.add("B");
        p.add("C");
        //Inserts the specified element into this priority queue.
        boolean b = p.offer("D");
        //Creating an Iterator Interface
        Iterator i = p.iterator();
        System.out.println("Given Queue is: ");
        while (i.hasNext()) {
            // Returns an iterator over the elements in this queue.
            System.out.print(i.next() "\t");
        }
        System.out.println();
        System.out.println(" Inserts the specified element: " + b);
    }
    }

Output of the program:-
Given Queue is:
A    B    D    Tewari    C    Girish   
 Inserts the specified element: true

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

HOME | COPYRIGHT | CONTACT US