SDEV200 — Ch 20 – Flashcards

Unlock all answers in this set

Unlock answers
question
All the update methods in the Java Collection framework are synchronized.
answer
false
question
Analyze the following code: public class Test { public static void main(String[] args) { PriorityQueue queue = newPriorityQueue( Arrays.asList(60, 10, 50, 30, 40, 20)); while (!queue.isEmpty()) System.out.print(queue.poll() + " "); } }
answer
The program displays 10 20 30 40 50 60
question
Suppose a list contains {"red", "green", "red", "green"}. What is the list after the following code? String element = "red"; for (int i = 0; i < list.size(); i++) if(list.get(i).equals(element)) { list.remove(element); i--; }
answer
{"green"}
question
Suppose list1 is an ArrayList and list2 is a LinkedList. Both contains 1 million double values. Analyze the following code: A: for (int i = 0; i
answer
Code fragment A runs faster than code fragment B.
question
The ________ method in the Queue interface retrieves, but does not remove, the head of this queue, returning null if this queue is empty.
answer
peek()
question
The iterator() method returns an instance of the ________ interface.
answer
Iterator
question
What is the printout of the following code? List list = new ArrayList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); for (int i = 0; i < list.size(); i++) System.out.print(list.remove(i));
answer
AC
question
java.util.Stack is a subclass of ________.
answer
java.util.AbstractList java.util.Vector
question
You can use index to traverse elements in an ArrayList.
answer
true
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New