Output of the code and how its work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Output of the code and how its work?

import java.util.*;   class TestCollection12{   public static void main(String args[]){   PriorityQueue<String> queue=new PriorityQueue<String>();   queue.add("Amit");   queue.add("Vijay");   queue.add("Karan");   queue.add("Jai");   queue.add("Rahul");   System.out.println("head:"+queue.element());   System.out.println("head:"+queue.peek());   System.out.println("iterating the queue elements:");   Iterator itr=queue.iterator();   while(itr.hasNext()){   System.out.println(itr.next());   }   queue.remove();   queue.poll();   System.out.println("after removing two elements:");   Iterator<String> itr2=queue.iterator();   while(itr2.hasNext()){  System.out.println(itr2.next());   }   }  

20th Jan 2020, 5:02 PM
Cheliyan
Cheliyan - avatar
2 Answers
20th Jan 2020, 8:07 PM
Denise Roßberg
Denise Roßberg - avatar
0
well for the output, just run it 😅 on how it works: do you know what a queue is? what are your guesses on how it works/parts of it work? 😁
20th Jan 2020, 6:17 PM
Anton Böhler
Anton Böhler - avatar