Return to site

JAVA CERTIFICATION QUESTION: TreeSets, LinkedLists, and ArrayDeques in Java

· java

Given this code:

Set<String> ss   = new TreeSet<>();
Queue<String> q  = new LinkedList<>();
Deque<String> dq = new ArrayDeque<>(1);
    
ss.add("John");
ss.add("Alan");
    
q.offer("Bert");
q.offer("Kathy");
    
dq.add("Jane");
dq.addFirst("Alex"); // line n1
    
ss.addAll(q);
dq.addAll(ss); // line n2
    
System.out.print(dq);

What is the result? Choose one.

A. Runtime exception at line n1

B. Runtime exception at line n2

C. [Jane, Alan, John, Bert, Kathy]

D. [Jane, Alan, Bert, John, Kathy]

E. [Alex, Jane, Alan, Bert, John, Kathy]

F. [Alex, Jane, Alan, John, Bert, Kathy]

 

 

 

 

 

 

Ǝ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ