+ 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()); } }
2 Antworten
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? 😁