What is the result?

Given that the elements of a PriorityQueue are ordered according to natural ordering, and:

import java.util.*;
public class GetInLine {
public static void main(String[] args) {
PriorityQueue<String> pq = new PriorityQueue<String>();
pq.add(“banana”);
pq.add(“pear”);
pq.add(“apple”);
System.out.println(pq.poll() + ” ” + pq.peek());
}
}

What is the result?

Given that the elements of a PriorityQueue are ordered according to natural ordering, and:

import java.util.*;
public class GetInLine {
public static void main(String[] args) {
PriorityQueue<String> pq = new PriorityQueue<String>();
pq.add(“banana”);
pq.add(“pear”);
pq.add(“apple”);
System.out.println(pq.poll() + ” ” + pq.peek());
}
}

What is the result?

A.
apple pear

B.
banana pear

C.
apple apple

D.
apple banana

E.
banana banana



Leave a Reply 0

Your email address will not be published. Required fields are marked *