Deck 15: The Java Collections Framework

Full screen (f)
exit full mode
Question
A collection that allows speedy insertion and removal of already-located elements in the middle of it is called a ____.

A) linked list
B) stack
C) set
D) queue
Use Space or
up arrow
down arrow
to flip the card.
Question
Which data structure would best be used for keeping track of a growing set of groceries to be purchased at the food market?

A) queue
B) stack
C) list
D) array
Question
The ArrayList class implements the ____.

A) Queue interface.
B) Set interface.
C) List interface.
D) Stack interface.
Question
Which of the following statements about linked lists is correct?

A) Once you have located the correct position, adding elements in the middle of a linked list is inefficient.
B) Visiting the elements of a linked list in random order is efficient.
C) When a node is removed, all nodes after the removed node must be moved down.
D) Linked lists should be used when you know the correct position and need to insert and remove elements efficiently.
Question
What type of access does a LinkedList provide for its elements?

A) sequential
B) semi-random
C) random
D) sorted
Question
A queue is a collection that ____.

A) remembers the order of elements, and allows elements to be added and removed only at one end.
B) does not remember the order of elements but allows elements to be added in any position.
C) remembers the order of elements and allows elements to be inserted in any position.
D) remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
Question
A linear search only requires ____ access.

A) sequential
B) random
C) sorted
D) arbitrary
Question
Consider the following code snippet:
LinkedList words = new LinkedList();
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?

A) abcdefghi
B) ghiabcdef
C) abcghidef
D) defghiabc
Question
A stack is a collection that ____.

A) remembers the order of elements, and allows elements to be added and removed only at one end.
B) does not remember the order of elements but allows elements to be added in any position.
C) remembers the order of elements and allows elements to be inserted in any position.
D) remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
Question
A collection that remembers the order of items, and allows items to be added and removed only at one end is called a ____.

A) list
B) stack
C) set
D) queue
Question
Which nodes need to be updated when we insert a new node to become the fourth node from the beginning of a doubly-linked list?

A) The current third node.
B) The current third and fourth nodes.
C) The current first node.
D) The current fourth and fifth nodes.
Question
A collection without an intrinsic order is called a ____.

A) list
B) stack
C) set
D) queue
Question
Rather than storing values in an array, a linked list uses a sequence of ____.

A) indexes
B) nodes
C) elements
D) accessors
Question
What is included in a linked list node?
I a reference to its neighboring nodes
II an array reference
III a data element

A) I
B) II
C) II and III
D) I and III
Question
A list is a collection that ____.

A) should be used when you need to remember the order of elements in the collection.
B) allows items to be added at one end and removed at the other end.
C) does not allow elements to be inserted in any position.
D) manages associations between keys and values.
Question
We might choose to use a linked list over an array list when we will not require frequent ____.
I random access
II inserting new elements
III removing of elements

A) I
B) II
C) III
D) II and III
Question
Consider the following code snippet:
LinkedList words = new LinkedList();
Words.addFirst("abc");
Words.addLast("def");
Words.addFirst("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?

A) abcdefghi
B) ghiabcdef
C) abcghidef
D) defghiabc
Question
A binary search requires ____ access.

A) sequential
B) random
C) sorted
D) arbitrary
Question
Which of the following algorithms would be efficiently executed using a LinkedList?

A) Tracking paths in a maze.
B) Binary search.
C) Remove first n/ 2 elements from a list of n elements.
D) Read n / 2 elements in random order from a list of n elements.
Question
A collection that allows items to be added only at one end and removed only at the other end is called a ____.

A) list
B) stack
C) set
D) queue
Question
Assume you are using a doubly-linked list data structure with many nodes. What is the minimum number of node references that are required to be modified to remove a node from the middle of the list? Consider the neighboring nodes.

A) 1
B) 2
C) 3
D) 4
Question
A linked list ____ encapsulates a position anywhere inside the linked list.

A) accessor
B) index
C) operation
D) iterator
Question
When using a list iterator, on which condition will the IllegalStateException be thrown?

A) Calling remove after calling next.
B) Calling add after calling previous.
C) Calling remove after calling add.
D) Calling previous after calling previous.
Question
When using a list iterator, on which condition will the NoSuchElementException be thrown?

A) Calling next when you are past the end of the list.
B) Calling next when the iterator points to the last element.
C) Calling remove after calling add.
D) Calling remove after calling previous.
Question
Which Java package contains the LinkedList class?

A) java.lang
B) java.util
C) java.collections
D) java.io
Question
In a linked list data structure, when does the reference to the first node need to be updated?
I inserting into an empty list
II deleting from a list with one node
III deleting an inner node

A) I
B) II
C) I and II
D) III
Question
What can a generic class be parameterized for?

A) properties
B) iterators
C) type
D) methods
Question
The nodes of a(n) ____ linked list class store two links: one to the next element and one to the previous one.

A) array
B) singly
C) doubly
D) randomly
Question
What is the meaning of the type parameter E, in the LinkedList code fragment?

A) The elements of the linked list are of class E.
B) The elements of the linked list are of any subclass of class E.
C) The elements of the linked list are any type supplied to the constructor.
D) The elements of the linked list are of class Object.
Question
You use a(n) ____ to access elements inside a linked list.

A) accessor
B) index
C) list iterator
D) queue
Question
The term ____ is used in computer science to describe an access pattern in which the elements are accessed in arbitrary order.

A) sequential access
B) random access
C) sorted access
D) arbitrary access
Question
Assume you have created a linked list named myList that currently holds some number of String objects. Which of the following statements correctly adds a new element to the beginning of myList?

A) myList.addFirst("Harry");
B) myList.add("Harry");
C) myList.insert("Harry");
D) myList.put("Harry");
Question
A linked list allows ____ access, but you need to ask the list for an iterator.

A) sequential
B) random
C) sorted
D) arbitrary
Question
Assume you have created a linked list name myList that currently holds some number of String objects. Which of the following statements correctly removes an element from the end of myList?

A) myList.remove();
B) myList.removeLast();
C) myList.getLast();
D) myList.pop();
Question
When using a list iterator, on which condition will the IllegalStateException be thrown?

A) Calling remove after calling next.
B) Calling next after calling previous.
C) Calling remove after calling remove.
D) Calling remove after calling previous.
Question
Consider the code snippet shown below. Assume that employeeNames is an instance of type LinkedList.
For (String name : employeeNames)
{
// Do something with name here
}
Which element(s) of employeeNames does this loop process?

A) no elements
B) all elements
C) elements meeting a condition
D) the most recently added elements
Question
Which method is NOT part of the ListIterator generic class?

A) hasNext
B) hasMore
C) hasPrevious
D) add
Question
Which method is NOT part of the ListIterator interface?

A) delete
B) add
C) next
D) previous
Question
Which of the following statements about the LinkedList class is correct?

A) When you use the add method, the new element is inserted before the iterator, and the iterator position is advanced by one position.
B) When you use the add method, the new element is inserted after the iterator, and the iterator position is advanced by one position.
C) When you use the add method, the new element is inserted before the iterator, and the iterator position is not moved
D) When you use the add method, the new element is inserted after the iterator, and the iterator position is not moved.
Question
A(n) ____ is a data structure used for collecting a sequence of objects that allows efficient addition and removal of already-located elements in the middle of the sequence.

A) stack
B) queue
C) linked list
D) priority queue
Question
Complete the following code, which is intended to print out all key/value pairs in a map named myMap that contains String data for student IDs and names:
Map myMap = new HashMap();
) . .
Set mapKeySet = myMap.keySet();
For (String aKey : mapKeySet)
{
___________________________;
System.out.println("ID: " + aKey + "->" + name);
}

A) String name = myMap.get(aKey);
B) String name = myMap.next(aKey);
C) String name = MapKeySet.get(aKey);
D) String name = MapKeySet.next(aKey);
Question
Consider the following code snippet:
Map scores;
If you need to visit the keys in sorted order, which of the following statements will create a structure to support this?

A) scores = new HashMap;
B) scores = new TreeMap;
C) scores = new Map;
D) scores = new HashTable;
Question
Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly remove an element from myMap?

A) myMap.get(3);
B) myMap.remove(3);
C) myMap.pop(3);
D) myMap.delete(3);
Question
Which of the following statements about sets is correct?

A) Inserting and removing elements that have already been located is faster with a list than with a set.
B) A set allows duplicate values.
C) You can add an element to a specific position within a set.
D) A set is a collection of unique elements organized for efficiency.
Question
Which of the following statements about the TreeSet class is NOT correct?

A) Elements are stored in sorted order.
B) Elements are arranged in linear fashion.
C) Elements are stored in nodes.
D) To use a TreeSet, it must be possible to compare the elements.
Question
Which of the following statements about data structures is correct?

A) Inserting and removing elements that have already been located is faster with a list than with a set.
B) Accessing elements in a linked list in a random fashion is efficient.
C) Adding and removing already-located elements in the middle of a linked list is efficient.
D) A set is an ordered collection of unique elements.
Question
Which of the following statements about manipulating objects in a map is NOT correct?

A) Use the add method to add a new element to the map.
B) Use the get method to retrieve a value from the map.
C) Use the keyset method to get the set of keys for the map.
D) Use the remove method to remove a value from the map.
Question
To create a TreeSet for a class of objects, the object class must ____.

A) create an iterator.
B) implement the Comparable interface.
C) implement the Set interface.
D) create a Comparator object.
Question
Which of the following statements about manipulating objects in a set is correct?

A) If you try to add an element that already exists, an exception will occur.
B) If you try to remove an element that does not exist, an exception will occur.
C) You can add an element at the position indicated by an iterator.
D) A set iterator visits elements in the order in which the set implementation keeps them.
Question
Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly retrieve the value of an element from myMap by using its key?

A) myMap.get("apple");
B) myMap.peek("apple");
C) myMap.get(3);
D) myMap.peek(3);
Question
Consider the following code snippet:
LinkedList myLList = new LinkedList();
MyLList.add("Mary");
MyLList.add("John");
MyLList.add("Sue");
ListIterator iterator = myLList.listIterator();
Iterator.next();
Iterator.next();
Iterator.add("Robert");
Iterator.previous();
Iterator.previous();
Iterator.remove();
System.out.println(myLList);
What will be printed when this code is executed?

A) [Mary, John, Robert, Sue]
B) [Mary, John, Sue]
C) [Mary, Robert, Sue]
D) [John, Robert, Sue]
Question
Assume that you have declared a set named mySet to hold String elements. Which of the following statements will correctly remove an element from mySet?

A) mySet.get("apple");
B) mySet.remove("apple");
C) mySet.pop("apple");
D) mySet.delete("apple");
Question
Consider the following code snippet:
Map scores;
You expect to retrieve elements randomly by key, and want fastest retrieval times. Which of the following statements will create a structure to support this?

A) scores = new HashMap;
B) scores = new TreeMap;
C) scores = new Map;
D) scores = new TreeSet;
Question
Which of the following statements about manipulating objects in a set is correct?

A) If you try to add an element that already exists, an exception will occur.
B) A set iterator visits elements in the order in which they were added to the set.
C) You can add an element at the position indicated by an iterator.
D) You can remove an element at the position indicated by an iterator.
Question
Which of the following statements about hash tables is NOT correct?

A) Elements are grouped into smaller collections that share the same characteristic.
B) You can form hash tables holding objects of type String.
C) You can add an element to a specific position within a hash table.
D) The value used to locate an element in a hash table is called a hash code.
Question
Which of the following statements about manipulating objects in a map is NOT correct?

A) If you attempt to retrieve a value with a key that is not associated with any value, you will receive a null result.
B) You cannot change the value of an existing association in the map; you must delete it and re-add it with the new values.
C) Use the get method to retrieve a value associated with a key in the map.
D) Use the put method to add an element to the map.
Question
Assume that you have declared a set named mySet to hold String elements. Which of the following statements will correctly insert an element into mySet?

A) mySet.insert("apple");
B) mySet.put(apple");
C) mySet.push("apple");
D) mySet.add("apple");
Question
Complete the following code, which is intended to print out all key/value pairs in a map named myMap that contains String data for student IDs and names:
Map myMap = new HashMap();
) . .
_______________________________
For (String aKey : mapKeySet)
{
String name = myMap.get(aKey);
System.out.println("ID: " + aKey + "->" + name);
}

A) Map mapKeySet = myMap.keySet();
B) Set mapKeySet = myMap.keySet();
C) Set mapKeySet = myMap.getKeySet();
D) Set mapKeySet = myMap.keySet();
Question
Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly insert an element into myMap?

A) myMap.insert(3, "apple");
B) myMap.put(3, "apple");
C) myMap.push(3, "apple");
D) myMap.add(3, "apple");
Question
Complete the following code snippet, which is intended to determine if a specific value in a variable named targetWord appears in a set of String values named mySet:
For (String aWord : mySet)
{
_______________________
{
System.out.println ("The word " + targetWord + " was found.");
}
)

A) if (mySet.equalsIgnoreCase(targetWord))
B) if (mySet == targetWord)
C) if (mySet.contains(targetWord))
D) if (mySet.get(targetWord))
Question
You need to access values in the opposite order in which they were added (last in, first out), and not randomly. Which collection type should you use?

A) Map
B) Hashtable
C) Stack
D) Queue
Question
You need to access values using a key, and the keys must be sorted. Which collection type should you use?

A) TreeMap
B) ArrayList
C) HashMap
D) Queue
Question
You need to write a program to build and maintain an address book. Since the program must support the possibility of having duplicate names, which data structure would be most appropriate to model this situation?

A) map
B) stack
C) queue
D) linked list
Question
Which of the following algorithms would be efficiently executed on an ArrayList?

A) add 1 element to the middle of a list with n elements
B) add n / 2 elements to a list with n / 2 elements
C) remove first n / 2 elements from a list of n elements
D) read n / 2 elements in random order from a list of n elements
Question
Which of the following correctly declares a stack that will hold String elements?

A) Stack s = new Stack();
B) Stack s = new Stack();
C) String s = new Stack();
D) String s = new Stack();
Question
You need to access values in objects by a key that is not part of the object. Which collection type should you use?

A) Map
B) Hashtable
C) ArrayList
D) Queue
Question
An Undo feature in a word processor program that allows you to reverse a previously completed command is probably implemented using which structure type?

A) queue
B) linked list
C) stack
D) hash table
Question
You have decided to store objects of a class in a TreeSet structure. Which of the following statements is correct?

A) If the object class implements the Comparable interface, and the sort order in the compare method is acceptable, you do not have to do anything else.
B) If the object class implements the Comparable interface, and the sort order in the compareTo method is acceptable, you do not have to do anything else.
C) If the object class implements the Comparable interface, and the sort order in the compare method is acceptable, you must create a comparator object.
D) If the object class implements the Comparable interface, and the sort order in the compareTo method is acceptable, you must create a comparator object.
Question
Which of the following statements about stacks is correct?

A) A stack implements first-in, first-out retrieval.
B) A stack implements random retrieval.
C) A stack implements last-in, first-out retrieval.
D) A stack stores elements in sorted order.
Question
You intend to use a hash set with your own object class. Which of the following statements is NOT correct?

A) You do not have to do anything additional. You can use the hashCode function of the Object class.
B) You can create your own function to compute a hashCode value.
C) You can override the hashCode method in the Object class to provide your own hashCode method.
D) Your class's hashCode method does not need to be compatible with its equals method.
Question
You need to access values by an integer position. Which collection type should you use?

A) Map
B) Hashtable
C) ArrayList
D) Queue
Question
You want to enumerate all of the keys in a map named myMap whose keys are type String. Which of the following statements will allow you to do this?

A) Set keySet = myMap.keySet();
For (String key : keySet) {. . . }
B) Set keySet = myMap.getKeys();
For (String key : keySet) {. . . }
C) Set keySet = myMap.keys();
For (String key : keySet) {. . . }
D) Set keySet = myMap.getKeySet();
For (String key : keySet) {. . . }
Question
Which data structure would best be used for storing a set of numbers and sorting them in ascending order?

A) queue
B) stack
C) list
D) array
Question
What operation is least efficient in a LinkedList?

A) Adding an element in a position that has already been located.
B) Linear traversal step.
C) Removing an element when the element's position has already been located.
D) Random access of an element.
Question
You need to write a program to manage a waiting list of patrons at a restaurant. Which data structure would be most appropriate to model this situation?

A) map
B) stack
C) queue
D) linked list
Question
You need to access values in the order in which they were added (first in, first out), and not randomly. Which collection type should you use?

A) Map
B) Hashtable
C) Stack
D) Queue
Question
You need to write a program to simulate the effect of adding an additional cashier in a supermarket to reduce the length of time customers must wait to check out. Which data structure would be most appropriate to simulate the waiting customers?

A) map
B) stack
C) queue
D) linked list
Question
Which of the following statements about hash functions is NOT correct?

A) A hash function produces a unique integer-valued hash code value for each distinct object.
B) A good hash function will minimize the number of objects that are assigned the same hash code.
C) Using a prime number as a hash multiplier will produce better hash codes.
D) If you supply your own hashCode method for a class, it must be compatible with that class's equals method.
Question
You need to access values by their position. Which collection type should you use?

A) TreeSet
B) ArrayList
C) Stack
D) Queue
Question
You need to write a program to build and maintain a catalog of college courses that are associated with specific majors. Which data structure would be most appropriate to model this situation?

A) map
B) stack
C) queue
D) linked list
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/100
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 15: The Java Collections Framework
1
A collection that allows speedy insertion and removal of already-located elements in the middle of it is called a ____.

A) linked list
B) stack
C) set
D) queue
A
2
Which data structure would best be used for keeping track of a growing set of groceries to be purchased at the food market?

A) queue
B) stack
C) list
D) array
C
3
The ArrayList class implements the ____.

A) Queue interface.
B) Set interface.
C) List interface.
D) Stack interface.
C
4
Which of the following statements about linked lists is correct?

A) Once you have located the correct position, adding elements in the middle of a linked list is inefficient.
B) Visiting the elements of a linked list in random order is efficient.
C) When a node is removed, all nodes after the removed node must be moved down.
D) Linked lists should be used when you know the correct position and need to insert and remove elements efficiently.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
5
What type of access does a LinkedList provide for its elements?

A) sequential
B) semi-random
C) random
D) sorted
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
6
A queue is a collection that ____.

A) remembers the order of elements, and allows elements to be added and removed only at one end.
B) does not remember the order of elements but allows elements to be added in any position.
C) remembers the order of elements and allows elements to be inserted in any position.
D) remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
7
A linear search only requires ____ access.

A) sequential
B) random
C) sorted
D) arbitrary
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
8
Consider the following code snippet:
LinkedList words = new LinkedList();
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?

A) abcdefghi
B) ghiabcdef
C) abcghidef
D) defghiabc
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
9
A stack is a collection that ____.

A) remembers the order of elements, and allows elements to be added and removed only at one end.
B) does not remember the order of elements but allows elements to be added in any position.
C) remembers the order of elements and allows elements to be inserted in any position.
D) remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
10
A collection that remembers the order of items, and allows items to be added and removed only at one end is called a ____.

A) list
B) stack
C) set
D) queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
11
Which nodes need to be updated when we insert a new node to become the fourth node from the beginning of a doubly-linked list?

A) The current third node.
B) The current third and fourth nodes.
C) The current first node.
D) The current fourth and fifth nodes.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
12
A collection without an intrinsic order is called a ____.

A) list
B) stack
C) set
D) queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
13
Rather than storing values in an array, a linked list uses a sequence of ____.

A) indexes
B) nodes
C) elements
D) accessors
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
14
What is included in a linked list node?
I a reference to its neighboring nodes
II an array reference
III a data element

A) I
B) II
C) II and III
D) I and III
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
15
A list is a collection that ____.

A) should be used when you need to remember the order of elements in the collection.
B) allows items to be added at one end and removed at the other end.
C) does not allow elements to be inserted in any position.
D) manages associations between keys and values.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
16
We might choose to use a linked list over an array list when we will not require frequent ____.
I random access
II inserting new elements
III removing of elements

A) I
B) II
C) III
D) II and III
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
17
Consider the following code snippet:
LinkedList words = new LinkedList();
Words.addFirst("abc");
Words.addLast("def");
Words.addFirst("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?

A) abcdefghi
B) ghiabcdef
C) abcghidef
D) defghiabc
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
18
A binary search requires ____ access.

A) sequential
B) random
C) sorted
D) arbitrary
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following algorithms would be efficiently executed using a LinkedList?

A) Tracking paths in a maze.
B) Binary search.
C) Remove first n/ 2 elements from a list of n elements.
D) Read n / 2 elements in random order from a list of n elements.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
20
A collection that allows items to be added only at one end and removed only at the other end is called a ____.

A) list
B) stack
C) set
D) queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
21
Assume you are using a doubly-linked list data structure with many nodes. What is the minimum number of node references that are required to be modified to remove a node from the middle of the list? Consider the neighboring nodes.

A) 1
B) 2
C) 3
D) 4
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
22
A linked list ____ encapsulates a position anywhere inside the linked list.

A) accessor
B) index
C) operation
D) iterator
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
23
When using a list iterator, on which condition will the IllegalStateException be thrown?

A) Calling remove after calling next.
B) Calling add after calling previous.
C) Calling remove after calling add.
D) Calling previous after calling previous.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
24
When using a list iterator, on which condition will the NoSuchElementException be thrown?

A) Calling next when you are past the end of the list.
B) Calling next when the iterator points to the last element.
C) Calling remove after calling add.
D) Calling remove after calling previous.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
25
Which Java package contains the LinkedList class?

A) java.lang
B) java.util
C) java.collections
D) java.io
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
26
In a linked list data structure, when does the reference to the first node need to be updated?
I inserting into an empty list
II deleting from a list with one node
III deleting an inner node

A) I
B) II
C) I and II
D) III
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
27
What can a generic class be parameterized for?

A) properties
B) iterators
C) type
D) methods
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
28
The nodes of a(n) ____ linked list class store two links: one to the next element and one to the previous one.

A) array
B) singly
C) doubly
D) randomly
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
29
What is the meaning of the type parameter E, in the LinkedList code fragment?

A) The elements of the linked list are of class E.
B) The elements of the linked list are of any subclass of class E.
C) The elements of the linked list are any type supplied to the constructor.
D) The elements of the linked list are of class Object.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
30
You use a(n) ____ to access elements inside a linked list.

A) accessor
B) index
C) list iterator
D) queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
31
The term ____ is used in computer science to describe an access pattern in which the elements are accessed in arbitrary order.

A) sequential access
B) random access
C) sorted access
D) arbitrary access
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
32
Assume you have created a linked list named myList that currently holds some number of String objects. Which of the following statements correctly adds a new element to the beginning of myList?

A) myList.addFirst("Harry");
B) myList.add("Harry");
C) myList.insert("Harry");
D) myList.put("Harry");
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
33
A linked list allows ____ access, but you need to ask the list for an iterator.

A) sequential
B) random
C) sorted
D) arbitrary
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
34
Assume you have created a linked list name myList that currently holds some number of String objects. Which of the following statements correctly removes an element from the end of myList?

A) myList.remove();
B) myList.removeLast();
C) myList.getLast();
D) myList.pop();
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
35
When using a list iterator, on which condition will the IllegalStateException be thrown?

A) Calling remove after calling next.
B) Calling next after calling previous.
C) Calling remove after calling remove.
D) Calling remove after calling previous.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
36
Consider the code snippet shown below. Assume that employeeNames is an instance of type LinkedList.
For (String name : employeeNames)
{
// Do something with name here
}
Which element(s) of employeeNames does this loop process?

A) no elements
B) all elements
C) elements meeting a condition
D) the most recently added elements
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
37
Which method is NOT part of the ListIterator generic class?

A) hasNext
B) hasMore
C) hasPrevious
D) add
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
38
Which method is NOT part of the ListIterator interface?

A) delete
B) add
C) next
D) previous
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following statements about the LinkedList class is correct?

A) When you use the add method, the new element is inserted before the iterator, and the iterator position is advanced by one position.
B) When you use the add method, the new element is inserted after the iterator, and the iterator position is advanced by one position.
C) When you use the add method, the new element is inserted before the iterator, and the iterator position is not moved
D) When you use the add method, the new element is inserted after the iterator, and the iterator position is not moved.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
40
A(n) ____ is a data structure used for collecting a sequence of objects that allows efficient addition and removal of already-located elements in the middle of the sequence.

A) stack
B) queue
C) linked list
D) priority queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
41
Complete the following code, which is intended to print out all key/value pairs in a map named myMap that contains String data for student IDs and names:
Map myMap = new HashMap();
) . .
Set mapKeySet = myMap.keySet();
For (String aKey : mapKeySet)
{
___________________________;
System.out.println("ID: " + aKey + "->" + name);
}

A) String name = myMap.get(aKey);
B) String name = myMap.next(aKey);
C) String name = MapKeySet.get(aKey);
D) String name = MapKeySet.next(aKey);
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
42
Consider the following code snippet:
Map scores;
If you need to visit the keys in sorted order, which of the following statements will create a structure to support this?

A) scores = new HashMap;
B) scores = new TreeMap;
C) scores = new Map;
D) scores = new HashTable;
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
43
Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly remove an element from myMap?

A) myMap.get(3);
B) myMap.remove(3);
C) myMap.pop(3);
D) myMap.delete(3);
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following statements about sets is correct?

A) Inserting and removing elements that have already been located is faster with a list than with a set.
B) A set allows duplicate values.
C) You can add an element to a specific position within a set.
D) A set is a collection of unique elements organized for efficiency.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following statements about the TreeSet class is NOT correct?

A) Elements are stored in sorted order.
B) Elements are arranged in linear fashion.
C) Elements are stored in nodes.
D) To use a TreeSet, it must be possible to compare the elements.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following statements about data structures is correct?

A) Inserting and removing elements that have already been located is faster with a list than with a set.
B) Accessing elements in a linked list in a random fashion is efficient.
C) Adding and removing already-located elements in the middle of a linked list is efficient.
D) A set is an ordered collection of unique elements.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
47
Which of the following statements about manipulating objects in a map is NOT correct?

A) Use the add method to add a new element to the map.
B) Use the get method to retrieve a value from the map.
C) Use the keyset method to get the set of keys for the map.
D) Use the remove method to remove a value from the map.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
48
To create a TreeSet for a class of objects, the object class must ____.

A) create an iterator.
B) implement the Comparable interface.
C) implement the Set interface.
D) create a Comparator object.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
49
Which of the following statements about manipulating objects in a set is correct?

A) If you try to add an element that already exists, an exception will occur.
B) If you try to remove an element that does not exist, an exception will occur.
C) You can add an element at the position indicated by an iterator.
D) A set iterator visits elements in the order in which the set implementation keeps them.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
50
Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly retrieve the value of an element from myMap by using its key?

A) myMap.get("apple");
B) myMap.peek("apple");
C) myMap.get(3);
D) myMap.peek(3);
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
51
Consider the following code snippet:
LinkedList myLList = new LinkedList();
MyLList.add("Mary");
MyLList.add("John");
MyLList.add("Sue");
ListIterator iterator = myLList.listIterator();
Iterator.next();
Iterator.next();
Iterator.add("Robert");
Iterator.previous();
Iterator.previous();
Iterator.remove();
System.out.println(myLList);
What will be printed when this code is executed?

A) [Mary, John, Robert, Sue]
B) [Mary, John, Sue]
C) [Mary, Robert, Sue]
D) [John, Robert, Sue]
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
52
Assume that you have declared a set named mySet to hold String elements. Which of the following statements will correctly remove an element from mySet?

A) mySet.get("apple");
B) mySet.remove("apple");
C) mySet.pop("apple");
D) mySet.delete("apple");
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
53
Consider the following code snippet:
Map scores;
You expect to retrieve elements randomly by key, and want fastest retrieval times. Which of the following statements will create a structure to support this?

A) scores = new HashMap;
B) scores = new TreeMap;
C) scores = new Map;
D) scores = new TreeSet;
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
54
Which of the following statements about manipulating objects in a set is correct?

A) If you try to add an element that already exists, an exception will occur.
B) A set iterator visits elements in the order in which they were added to the set.
C) You can add an element at the position indicated by an iterator.
D) You can remove an element at the position indicated by an iterator.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
55
Which of the following statements about hash tables is NOT correct?

A) Elements are grouped into smaller collections that share the same characteristic.
B) You can form hash tables holding objects of type String.
C) You can add an element to a specific position within a hash table.
D) The value used to locate an element in a hash table is called a hash code.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
56
Which of the following statements about manipulating objects in a map is NOT correct?

A) If you attempt to retrieve a value with a key that is not associated with any value, you will receive a null result.
B) You cannot change the value of an existing association in the map; you must delete it and re-add it with the new values.
C) Use the get method to retrieve a value associated with a key in the map.
D) Use the put method to add an element to the map.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
57
Assume that you have declared a set named mySet to hold String elements. Which of the following statements will correctly insert an element into mySet?

A) mySet.insert("apple");
B) mySet.put(apple");
C) mySet.push("apple");
D) mySet.add("apple");
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
58
Complete the following code, which is intended to print out all key/value pairs in a map named myMap that contains String data for student IDs and names:
Map myMap = new HashMap();
) . .
_______________________________
For (String aKey : mapKeySet)
{
String name = myMap.get(aKey);
System.out.println("ID: " + aKey + "->" + name);
}

A) Map mapKeySet = myMap.keySet();
B) Set mapKeySet = myMap.keySet();
C) Set mapKeySet = myMap.getKeySet();
D) Set mapKeySet = myMap.keySet();
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
59
Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly insert an element into myMap?

A) myMap.insert(3, "apple");
B) myMap.put(3, "apple");
C) myMap.push(3, "apple");
D) myMap.add(3, "apple");
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
60
Complete the following code snippet, which is intended to determine if a specific value in a variable named targetWord appears in a set of String values named mySet:
For (String aWord : mySet)
{
_______________________
{
System.out.println ("The word " + targetWord + " was found.");
}
)

A) if (mySet.equalsIgnoreCase(targetWord))
B) if (mySet == targetWord)
C) if (mySet.contains(targetWord))
D) if (mySet.get(targetWord))
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
61
You need to access values in the opposite order in which they were added (last in, first out), and not randomly. Which collection type should you use?

A) Map
B) Hashtable
C) Stack
D) Queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
62
You need to access values using a key, and the keys must be sorted. Which collection type should you use?

A) TreeMap
B) ArrayList
C) HashMap
D) Queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
63
You need to write a program to build and maintain an address book. Since the program must support the possibility of having duplicate names, which data structure would be most appropriate to model this situation?

A) map
B) stack
C) queue
D) linked list
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
64
Which of the following algorithms would be efficiently executed on an ArrayList?

A) add 1 element to the middle of a list with n elements
B) add n / 2 elements to a list with n / 2 elements
C) remove first n / 2 elements from a list of n elements
D) read n / 2 elements in random order from a list of n elements
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
65
Which of the following correctly declares a stack that will hold String elements?

A) Stack s = new Stack();
B) Stack s = new Stack();
C) String s = new Stack();
D) String s = new Stack();
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
66
You need to access values in objects by a key that is not part of the object. Which collection type should you use?

A) Map
B) Hashtable
C) ArrayList
D) Queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
67
An Undo feature in a word processor program that allows you to reverse a previously completed command is probably implemented using which structure type?

A) queue
B) linked list
C) stack
D) hash table
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
68
You have decided to store objects of a class in a TreeSet structure. Which of the following statements is correct?

A) If the object class implements the Comparable interface, and the sort order in the compare method is acceptable, you do not have to do anything else.
B) If the object class implements the Comparable interface, and the sort order in the compareTo method is acceptable, you do not have to do anything else.
C) If the object class implements the Comparable interface, and the sort order in the compare method is acceptable, you must create a comparator object.
D) If the object class implements the Comparable interface, and the sort order in the compareTo method is acceptable, you must create a comparator object.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
69
Which of the following statements about stacks is correct?

A) A stack implements first-in, first-out retrieval.
B) A stack implements random retrieval.
C) A stack implements last-in, first-out retrieval.
D) A stack stores elements in sorted order.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
70
You intend to use a hash set with your own object class. Which of the following statements is NOT correct?

A) You do not have to do anything additional. You can use the hashCode function of the Object class.
B) You can create your own function to compute a hashCode value.
C) You can override the hashCode method in the Object class to provide your own hashCode method.
D) Your class's hashCode method does not need to be compatible with its equals method.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
71
You need to access values by an integer position. Which collection type should you use?

A) Map
B) Hashtable
C) ArrayList
D) Queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
72
You want to enumerate all of the keys in a map named myMap whose keys are type String. Which of the following statements will allow you to do this?

A) Set keySet = myMap.keySet();
For (String key : keySet) {. . . }
B) Set keySet = myMap.getKeys();
For (String key : keySet) {. . . }
C) Set keySet = myMap.keys();
For (String key : keySet) {. . . }
D) Set keySet = myMap.getKeySet();
For (String key : keySet) {. . . }
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
73
Which data structure would best be used for storing a set of numbers and sorting them in ascending order?

A) queue
B) stack
C) list
D) array
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
74
What operation is least efficient in a LinkedList?

A) Adding an element in a position that has already been located.
B) Linear traversal step.
C) Removing an element when the element's position has already been located.
D) Random access of an element.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
75
You need to write a program to manage a waiting list of patrons at a restaurant. Which data structure would be most appropriate to model this situation?

A) map
B) stack
C) queue
D) linked list
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
76
You need to access values in the order in which they were added (first in, first out), and not randomly. Which collection type should you use?

A) Map
B) Hashtable
C) Stack
D) Queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
77
You need to write a program to simulate the effect of adding an additional cashier in a supermarket to reduce the length of time customers must wait to check out. Which data structure would be most appropriate to simulate the waiting customers?

A) map
B) stack
C) queue
D) linked list
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
78
Which of the following statements about hash functions is NOT correct?

A) A hash function produces a unique integer-valued hash code value for each distinct object.
B) A good hash function will minimize the number of objects that are assigned the same hash code.
C) Using a prime number as a hash multiplier will produce better hash codes.
D) If you supply your own hashCode method for a class, it must be compatible with that class's equals method.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
79
You need to access values by their position. Which collection type should you use?

A) TreeSet
B) ArrayList
C) Stack
D) Queue
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
80
You need to write a program to build and maintain a catalog of college courses that are associated with specific majors. Which data structure would be most appropriate to model this situation?

A) map
B) stack
C) queue
D) linked list
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 100 flashcards in this deck.