Exam 15: The Java Collections Framework

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

A collection without an intrinsic order is called a ____.

(Multiple Choice)
4.9/5
(42)

Select an appropriate expression to complete the method below, which is designed to print the element at the bottom of a Stack collection. The contents of the original stack are restored before the method terminates. It is safe to assume that the original stack contains at least one element. public static void printBottom(Stack<String> theStack) { Stack<String> anotherStack = new Stack<String>(); While (theStack.size() > 0) { AnotherStack.push(theStack.pop()); } ____________________________ While (anotherStack.size() > 0) { TheStack.push(anotherStack.pop()); } }

(Multiple Choice)
4.8/5
(40)

Which of the following statements about a priority queue structure is correct?

(Multiple Choice)
4.7/5
(39)

Select an appropriate expression to complete the method below. The method should return the number of times that the string stored in name appears in theList. public static int count(LinkedList<String> theList, String name) { Int number = 0; Iterator<String> iter = theList.iterator(); While (______________________) { If (iter.next().equals(name)) { Number++; } } Return number; }

(Multiple Choice)
4.9/5
(40)

Consider the following code snippet: Stack<String> stringStack = new Stack<String>(); StringStack.push("ab"); StringStack.push("abc"); StringStack.push("a"); While (stringStack.size() > 0) { System.out.print(stringStack.pop() + ","); } What output will be produced when this code is executed?

(Multiple Choice)
4.8/5
(35)

Consider the following code snippet: LinkedList<String> words = new LinkedList<String>(); Words.addLast("abc"); Words.addLast("def"); Words.addLast("ghi"); System.out.print(words.removeLast()); System.out.print(words.removeFirst()); System.out.print(words.removeLast()); What will this code print when it is executed?

(Multiple Choice)
4.9/5
(48)

Which of the following statements about manipulating objects in a set is correct?

(Multiple Choice)
4.8/5
(38)

Which operations from the list data structure could be used to implement the push and pop operations of a stack data structure? I addLast II addFirst III removeFirst

(Multiple Choice)
4.8/5
(40)

Which Java package contains the LinkedList class?

(Multiple Choice)
4.7/5
(34)

Which method is NOT part of the ListIterator generic class?

(Multiple Choice)
4.9/5
(42)

An Undo feature in a word processor program that allows you to reverse a previously completed command is probably implemented using which structure type?

(Multiple Choice)
4.9/5
(41)

A linked list allows ____ access, but you need to ask the list for an iterator.

(Multiple Choice)
4.8/5
(37)

Select an appropriate expression to complete the following code segment, which is designed to print a message if the string stored in name is the first element of the players linked list. LinkedList<String> players = new LinkedList<String>(); // code to add elements to the linked list If ______________________________________ System.out.print(name + " is the first player on the list.");

(Multiple Choice)
4.9/5
(43)

Assume that you have declared a stack named myStack to hold String elements. Which of the following statements will correctly retrieve the top element from myStack without removing it?

(Multiple Choice)
4.9/5
(41)

What can a generic class be parameterized for?

(Multiple Choice)
4.7/5
(42)

Suppose we create a deque (double-ended queue) data structure. It is basically a queue, with its addLast and removeFirst operations, but we also add the addFirst and removeLast operations. If a line at the grocery store resembles a deque more than a queue, what is the most likely reason? I the cashier is very fast II the line is very long III the cashier is very slow

(Multiple Choice)
4.8/5
(40)

Consider the following code snippet: Stack<String> words1 = new Stack<String>(); ArrayList<String> words3 = new ArrayList<String>(); Words1.push("abc"); Words1.push("def"); Words1.push("ghi"); While (!words1.empty()) { Words3.add(words1.pop()); } Int i = words3.size() - 1; While (i >= 0) { System.out.print(words3.remove(i)); I--; } What will this code print when it is executed?

(Multiple Choice)
4.9/5
(35)

Select an appropriate expression to complete the following method, which is designed to return the sum of the two smallest values in the parameter array numbers. public static int sumTwoLowestElements(int[] numbers) { PriorityQueue<Integer> values = new PriorityQueue<Integer>(); For (int num: numbers) { Values.add(num); } ______________________ }

(Multiple Choice)
4.8/5
(33)

What type of access does a LinkedList provide for its elements?

(Multiple Choice)
4.9/5
(34)

You have decided to store objects of a class in a TreeSet structure. Which of the following statements is correct?

(Multiple Choice)
4.8/5
(44)
Showing 21 - 40 of 110
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)