Java

Program to add all the elements of a priority queues to another priority queue.

Program to add all the elements of a priority queues to another priority queue.
import java.util.*;
public class demo1 
{
 public static void main(String[] args) 
 {
  PriorityQueue<String> P_queue=new PriorityQueue<String>();  
  P_queue.add("C#");
  P_queue.add("C++");
  P_queue.add("Java");
  P_queue.add("Python");
  P_queue.add("Ruby");
  System.out.println("Priority Queue: "+P_queue);
  
  PriorityQueue<String> P_queue1 = new PriorityQueue<String>();  
  P_queue1.add("HTML");
  P_queue1.add("Perl");
  System.out.println("Priority Queue1: "+P_queue1);
    
  P_queue.addAll(P_queue1);
  System.out.println("New Priority Queue: "+P_queue);
 }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.