Deck 15: The Java Collections Framework

Full screen (f)
exit full mode
Question
A linear search only requires ____ access.
A.sorted
B.arbitrary
C.sequential
D.random
Use Space or
up arrow
down arrow
to flip the card.
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.remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
C.does not remember the order of elements but allows elements to be added in any position.
D.remembers the order of elements and allows elements to be inserted in any position.
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.II only
B.I and III only
C.I only
D.II and III only
Question
Which of the following algorithms would be efficiently executed using a LinkedList?
A.Remove first n/ 2 elements from a list of n elements.
B.Read n / 2 elements in random order from a list of n elements.
C.Tracking paths in a maze.
D.Binary search.
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
Question
The ArrayList class implements the ____ interface.
A.Stack
B.Queue
C.List
D.Set
Question
A stack is a collection that ____.
A.does not remember the order of elements but allows elements to be added in any position.
B.remembers the order of elements, and allows elements to be added and removed only at one end.
C.remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
D.remembers the order of elements and allows elements to be inserted in any position.
Question
Which of the following statements about linked lists is correct?
A.When a node is removed, all nodes after the removed node must be moved down.
B.Visiting the elements of a linked list in random order is efficient.
C.Linked lists should be used when you know the correct position and need to insert and remove elements efficiently.
D.Even if you have located the correct position, adding elements in the middle of a linked list is inefficient.
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 and fourth nodes.
B.The current fourth and fifth nodes.
C.The current first node.
D.The current third node.
Question
Which data structure would best be used for keeping track of groceries to be purchased at the food market?
A.stack
B.queue
C.list
D.array
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.III only
B.II only
C.II and III only
D.I only
Question
Rather than storing values in an array, a linked list uses a sequence of ____.
A.accessors
B.nodes
C.elements
D.indexes
Question
A list is a collection that ____.
A.does not allow elements to be inserted in any position.
B.only allows items to be added at one end and removed at the other end.
C.manages associations between keys and values.
D.should be used when you need to remember the order of elements in the collection.
Question
A collection without an intrinsic order is called a ____.
A.queue
B.stack
C.set
D.list
Question
Select an appropriate expression to complete the following code segment, which is designed to print a message if the string stored in name is part of the players collection. Select an appropriate expression to complete the following code segment, which is designed to print a message if the string stored in name is part of the players collection.   A.(players.contains(name)) B.(players.indexOf(name)) C.(players.search(name)) D.(players.equals(name))<div style=padding-top: 35px>
A.(players.contains(name))
B.(players.indexOf(name))
C.(players.search(name))
D.(players.equals(name))
Question
Consider the following code snippet: Consider the following code snippet:   What will this code print when it is executed? A.abcdefghi B.defghiabc C.ghiabcdef D.abcghidef<div style=padding-top: 35px> What will this code print when it is executed?
A.abcdefghi
B.defghiabc
C.ghiabcdef
D.abcghidef
Question
A binary search requires ____ access.
A.sorted
B.random
C.arbitrary
D.sequential
Question
A collection that allows items to be added only at one end and removed only at the other end is called a ____.
A.set
B.stack
C.queue
D.list
Question
What type of access does a LinkedList provide for its elements?
A.sorted
B.sequential
C.random
D.semi-random
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.queue
B.stack
C.list
D.set
Question
Which Java package contains the LinkedList class?
A.java.lang
B.java.io
C.java.collections
D.java.util
Question
Which method is NOT part of the ListIterator interface?
A.hasPrevious
B.hasMore
C.add
D.hasNext
Question
Select an appropriate expression to complete the following method, which is designed to visit the elements in theList and replace each occurrence of the string "hello" with the string "goodbye". Select an appropriate expression to complete the following method, which is designed to visit the elements in theList and replace each occurrence of the string hello with the string goodbye.   A.iterator.next() = goodbye; B.iterator.previous(goodbye); C.iterator.replace(hello, goodbye); D.iterator.set(goodbye);<div style=padding-top: 35px>
A.iterator.next() = "goodbye";
B.iterator.previous("goodbye");
C.iterator.replace("hello", "goodbye");
D.iterator.set("goodbye");
Question
When using a list iterator, on which condition will the IllegalStateException be thrown?
A.Calling next after calling previous.
B.Calling remove after calling previous.
C.Calling remove after calling remove.
D.Calling remove after calling next.
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.3
B.2
C.4
D.1
Question
Assume you have created a linked list named 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.getLast();
C.myList.pop();
D.myList.removeLast();
Question
Consider the code snippet shown below.Assume that employeeNames is an instance of type LinkedList. Consider the code snippet shown below.Assume that employeeNames is an instance of type LinkedList<String>.   Which element(s) of employeeNames does this loop process? A.elements meeting a condition B.the most recently added elements C.no elements D.all elements<div style=padding-top: 35px> Which element(s) of employeeNames does this loop process?
A.elements meeting a condition
B.the most recently added elements
C.no elements
D.all elements
Question
A ____ 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.queue
B.priority queue
C.stack
D.linked list
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.randomly
D.doubly
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.insert("Harry");
B.myList.addFirst("Harry");
C.myList.add("Harry");
D.myList.put("Harry");
Question
You use a(n) ____ to access elements inside a linked list.
A.queue
B.accessor
C.list iterator
D.index
Question
When using the add method of the ListIterator to add an element to a linked list, which of the following statements is correct?
A.The new element is inserted before the iterator position, and a subsequent call to next would be unaffected.
B.The new element is inserted after the iterator position, and a subsequent call to next would return the new element.
C.The new element is inserted after the iterator position, and a subsequent call to previous would be unaffected.
D.The new element is inserted before the iterator position, and a subsequent call to next would return the new element.
Question
Consider the following code snippet: Consider the following code snippet:   What will this code print when it is executed? A.ghiabcdef B.defghiabc C.abcdefghi D.abcghidef<div style=padding-top: 35px> What will this code print when it is executed?
A.ghiabcdef
B.defghiabc
C.abcdefghi
D.abcghidef
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.sorted access
C.arbitrary access
D.random access
Question
What can a generic class be parameterized for?
A.methods
B.iterators
C.type
D.properties
Question
When using a list iterator, on which condition will the IllegalStateException be thrown?
A.Calling remove after calling next.
B.Calling remove after calling add.
C.Calling add after calling previous.
D.Calling previous after calling previous.
Question
Which method is NOT part of the ListIterator interface?
A.next
B.delete
C.add
D.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 remove after calling add.
C.Calling remove after calling previous.
D.Calling next when the iterator points to the last element.
Question
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. 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.   A.theList.next() != null B.iter.hasNext() C.theList.hasNext() D.iter.next() != null<div style=padding-top: 35px>
A.theList.next() != null
B.iter.hasNext()
C.theList.hasNext()
D.iter.next() != null
Question
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. 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.   A.(players.getFirst().equals(name)) B.(players[0].equals(name)) C.(players.contains(name)) D.(players.indexOf(name) == 1)<div style=padding-top: 35px>
A.(players.getFirst().equals(name))
B.(players[0].equals(name))
C.(players.contains(name))
D.(players.indexOf(name) == 1)
Question
Which of the following statements about manipulating objects in a map is NOT correct?
A.Use the remove method to remove a value from 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 add method to add a new 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 delete an element from mySet?
A.mySet.delete("apple");
B.mySet.remove("apple");
C.mySet.get("apple");
D.mySet.pop("apple");
Question
Select an appropriate declaration to complete the following code segment, which is designed to read strings from standard input and display them in increasing alphabetical order, excluding any duplicates. Select an appropriate declaration to complete the following code segment, which is designed to read strings from standard input and display them in increasing alphabetical order, excluding any duplicates.   A.LinkedList<String> words = new LinkedList<>(); B.Set<String> words = new TreeSet<>(); C.Set<String> words = new Set<>(); D.Set<String> words = new HashSet<>();<div style=padding-top: 35px>
A.LinkedList words = new LinkedList<>();
B.Set words = new TreeSet<>();
C.Set words = new Set<>();
D.Set words = new HashSet<>();
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.The value used to locate an element in a hash table is called a hash code.
D.You can add an element to a specific position within a hash table.
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: 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:   A.String name = myMap.next(aKey); B.String name = MapKeySet.get(aKey); C.String name = myMap.get(aKey); D.String name = MapKeySet.next(aKey);<div style=padding-top: 35px>
A.String name = myMap.next(aKey);
B.String name = MapKeySet.get(aKey);
C.String name = myMap.get(aKey);
D.String name = MapKeySet.next(aKey);
Question
Consider the following code snippet: Consider the following code snippet:   What will be printed when this code is executed? A.[Mary, John, Robert, Sue] B.[John, Robert, Sue] C.[Mary, Robert, Sue] D.[Mary, John, Sue]<div style=padding-top: 35px> What will be printed when this code is executed?
A.[Mary, John, Robert, Sue]
B.[John, Robert, Sue]
C.[Mary, Robert, Sue]
D.[Mary, John, Sue]
Question
Assume that you have declared a map named myMap to hold String values with Integer keys.Which of the following statements will correctly delete an association from myMap?
A.myMap.remove(3);
B.myMap.remove("apple");
C.myMap.delete(3);
D.myMap.pop(3);
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 and II only
B.I only
C.II only
D.III only
Question
Which of the following statements about the TreeSet class is NOT correct?
A.Elements are stored in nodes.
B.Elements are arranged in linear fashion.
C.To use a TreeSet, it must be possible to compare the elements.
D.Elements are stored in sorted order.
Question
To create a TreeSet for a class of objects, the object class must ____.
A.implement the Set interface.
B.implement the Comparable interface.
C.create an iterator.
D.create a Comparator object.
Question
Which of the following statements about manipulating objects in a set is correct?
A.If you try to remove an element that does not exist, an exception will occur.
B.If you try to add an element that already exists, an exception will occur.
C.A set iterator visits elements in the order in which the set implementation keeps them.
D.You can add an element at the position indicated by an iterator.
Question
Which of the following statements about manipulating objects in a map is NOT correct?
A.Use the put method to add an element to the map.
B.If you attempt to retrieve a value with a key that is not associated with any value, you will receive a null result.
C.Use the get method to retrieve a value associated with a key in the map.
D.You cannot change the value of an existing association in the map; you must delete it and re-add it with the new values.
Question
Select an appropriate expression to complete the following method, which is designed to return the number of elements in the parameter array numbers.If a value appears more than once, it should be counted exactly once. Select an appropriate expression to complete the following method, which is designed to return the number of elements in the parameter array numbers.If a value appears more than once, it should be counted exactly once.   A.return numbers.length - values.size(); B.return values.size(); C.return numbers.length; D.return values.length();<div style=padding-top: 35px>
A.return numbers.length - values.size();
B.return values.size();
C.return numbers.length;
D.return values.length();
Question
Your program uses a Map structure to store a number of user ids and corresponding email addresses.Although each user must have a unique id, two or more users can share the same email address.Assuming that all entries in the map have valid email addresses, select an appropriate expression to complete the method below, which adds a new id and email address to the map only if the id is not already in use.If the id is already in use, an error message is printed. Your program uses a Map structure to store a number of user ids and corresponding email addresses.Although each user must have a unique id, two or more users can share the same email address.Assuming that all entries in the map have valid email addresses, select an appropriate expression to complete the method below, which adds a new id and email address to the map only if the id is not already in use.If the id is already in use, an error message is printed.   A.!currentEmail.equals(email) B.currentEmail.equals(email) C.currentEmail != null D.currentEmail == null<div style=padding-top: 35px>
A.!currentEmail.equals(email)
B.currentEmail.equals(email)
C.currentEmail != null
D.currentEmail == null
Question
Assume that you have declared a map named myMap to hold String values with Integer keys.Which of the following statements will correctly retrieve the value associated with a key from myMap?
A.myMap.peek(3);
B.myMap.get("apple");
C.myMap.peek("apple");
D.myMap.get(3);
Question
Which of the following statements about sets is correct?
A.Attempting to remove an element that is not in the set generates an exception.
B.You can add an element to a specific position within a set.
C.A set is a collection of unique elements organized for efficiency.
D.A set allows duplicate values.
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.put(apple");
B.mySet.insert("apple");
C.mySet.add("apple");
D.mySet.push("apple");
Question
Which of the following statements about manipulating objects in a set is correct?
A.A set iterator visits elements in the order in which they were added to the set.
B.You can remove an element at the position indicated by an iterator.
C.If you try to add an element that already exists, an exception will occur.
D.You can add an element at the position indicated by an iterator.
Question
Assume that you have declared a map named myMap to hold String values with Integer keys.Which of the following statements will correctly add an association into myMap?
A.myMap.insert(3, "apple");
B.myMap.add(3, "apple");
C.myMap.put(3, "apple");
D.myMap.push(3, "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: 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:   A.Map<String, String> mapKeySet = myMap.keySet(); B.Set<String, String> mapKeySet = myMap.keySet(); C.Set<String> mapKeySet = myMap.keySet(); D.Set<String> mapKeySet = myMap.getKeySet();<div style=padding-top: 35px>
A.Map mapKeySet = myMap.keySet();
B.Set mapKeySet = myMap.keySet();
C.Set mapKeySet = myMap.keySet();
D.Set mapKeySet = myMap.getKeySet();
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 Map<>;
C.scores = new TreeMap<>;
D.scores = new TreeSet<>;
Question
What operation is least efficient in a LinkedList?
A.Linear traversal step.
B.Random access of an element.
C.Adding an element in a position that has already been located.
D.Removing an element when the element's position has already been located.
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.linked list
D.queue
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.Hashtable
B.ArrayList
C.Map
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.getKeySet(); for (String key : keySet) {...}
B.Set keySet = myMap.keySet(); for (String key : keySet) {...}
C.Set keySet = myMap.keys(); for (String key : keySet) {...}
D.Set keySet = myMap.getKeys(); for (String key : keySet) {...}
Question
You need to access values by an integer position.Which collection type should you use?
A.Queue
B.Map
C.Hashtable
D.ArrayList
Question
You need to access values using a key, and the keys must be sorted.Which collection type should you use?
A.Queue
B.TreeMap
C.HashMap
D.ArrayList
Question
Which of the following algorithms would be efficiently executed on an ArrayList?
A.remove first n / 2 elements from a list of n elements
B.add 1 element to the middle of a list with n elements
C.add n / 2 elements to a list with n / 2 elements
D.read n / 2 elements in random order from a list of n elements
Question
Which of the following statements about hash functions is NOT correct?
A.Using a prime number as a hash multiplier will produce better hash codes.
B.If you supply your own hashCode method for a class, it must be compatible with that class's equals method.
C.A good hash function will minimize the number of objects that are assigned the same hash code.
D.A hash function produces a unique integer-valued hash code value for each distinct object.
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.stack
B.queue
C.hash table
D.linked list
Question
Assume that you have declared a stack named myStack to hold String elements.Which of the following statements will correctly add an element to myStack?
A.myStack.addItem("apple");
B.myStack.put("apple");
C.myStack.insert("apple");
D.myStack.push("apple");
Question
Which data structure would best be used for storing a set of numbers and sorting them in ascending order?
A.queue
B.array
C.stack
D.list
Question
You intend to use a hash set with your own object class.Which of the following statements is correct?
A.You cannot override the hashCode method in the Object class.
B.You can use the hash method of the Objects class to create your own hashCode method by combining the hash codes for the instance variables.
C.You can override the hash method for your class provided that it is compatible with its equals method.
D.Your class's hashCode method does not need to be compatible with its equals method.
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.Hashtable
B.Map
C.Queue
D.Stack
Question
Using the merge method of the Map interface, which statement correctly updates the wordCount map of type Map to count all of the occurrences of a word in a file?
A.wordCount.merge(word, 1, (k,v) -> v + 1);
B.word.merge(wordCount,(k,v) -> v + 1);
C.word.merge(wordCount, 1, (k,v) -> v + 1);
D.wordCount.merge(word,(k,v) -> v + 1);
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.Queue
B.Map
C.Stack
D.Hashtable
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 HashTable<>;
B.scores = new HashMap<>;
C.scores = new TreeMap<>;
D.scores = new Map<>;
Question
Using the merge method of the Map interface, which statement correctly updates the salesTotalByDept map of type Map to update the sales total for a dept by an integer sales value?
A.salesTotalByDept.merge(dept, sales,(d,s) -> s + 1);
B.sales.merge(salesTotalByDept, dept, (d,s) -> s + sales);
C.dept.merge(salesTotalByDept, sales, (d,s) -> s + sales);
D.salesTotalByDept.merge(dept, sales, (d,s) -> s + sales);
Question
Which of the following statements about stacks is correct?
A.A stack implements random retrieval.
B.A stack implements last-in, first-out retrieval.
C.A stack stores elements in sorted order.
D.A stack implements first-in, first-out retrieval.
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<>();
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/102
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 15: The Java Collections Framework
1
A linear search only requires ____ access.
A.sorted
B.arbitrary
C.sequential
D.random
sequential
2
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.remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
C.does not remember the order of elements but allows elements to be added in any position.
D.remembers the order of elements and allows elements to be inserted in any position.
remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
3
What is included in a linked list node?
I a reference to its neighboring nodes
II an array reference
III a data element
A.II only
B.I and III only
C.I only
D.II and III only
I and III only
4
Which of the following algorithms would be efficiently executed using a LinkedList?
A.Remove first n/ 2 elements from a list of n elements.
B.Read n / 2 elements in random order from a list of n elements.
C.Tracking paths in a maze.
D.Binary search.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
5
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
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
6
The ArrayList class implements the ____ interface.
A.Stack
B.Queue
C.List
D.Set
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
7
A stack is a collection that ____.
A.does not remember the order of elements but allows elements to be added in any position.
B.remembers the order of elements, and allows elements to be added and removed only at one end.
C.remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.
D.remembers the order of elements and allows elements to be inserted in any position.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following statements about linked lists is correct?
A.When a node is removed, all nodes after the removed node must be moved down.
B.Visiting the elements of a linked list in random order is efficient.
C.Linked lists should be used when you know the correct position and need to insert and remove elements efficiently.
D.Even if you have located the correct position, adding elements in the middle of a linked list is inefficient.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
9
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 and fourth nodes.
B.The current fourth and fifth nodes.
C.The current first node.
D.The current third node.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
10
Which data structure would best be used for keeping track of groceries to be purchased at the food market?
A.stack
B.queue
C.list
D.array
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
11
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.III only
B.II only
C.II and III only
D.I only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
12
Rather than storing values in an array, a linked list uses a sequence of ____.
A.accessors
B.nodes
C.elements
D.indexes
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
13
A list is a collection that ____.
A.does not allow elements to be inserted in any position.
B.only allows items to be added at one end and removed at the other end.
C.manages associations between keys and values.
D.should be used when you need to remember the order of elements in the collection.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
14
A collection without an intrinsic order is called a ____.
A.queue
B.stack
C.set
D.list
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
15
Select an appropriate expression to complete the following code segment, which is designed to print a message if the string stored in name is part of the players collection. Select an appropriate expression to complete the following code segment, which is designed to print a message if the string stored in name is part of the players collection.   A.(players.contains(name)) B.(players.indexOf(name)) C.(players.search(name)) D.(players.equals(name))
A.(players.contains(name))
B.(players.indexOf(name))
C.(players.search(name))
D.(players.equals(name))
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
16
Consider the following code snippet: Consider the following code snippet:   What will this code print when it is executed? A.abcdefghi B.defghiabc C.ghiabcdef D.abcghidef What will this code print when it is executed?
A.abcdefghi
B.defghiabc
C.ghiabcdef
D.abcghidef
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
17
A binary search requires ____ access.
A.sorted
B.random
C.arbitrary
D.sequential
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
18
A collection that allows items to be added only at one end and removed only at the other end is called a ____.
A.set
B.stack
C.queue
D.list
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
19
What type of access does a LinkedList provide for its elements?
A.sorted
B.sequential
C.random
D.semi-random
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
20
A collection that remembers the order of items, and allows items to be added and removed only at one end is called a ____.
A.queue
B.stack
C.list
D.set
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
21
Which Java package contains the LinkedList class?
A.java.lang
B.java.io
C.java.collections
D.java.util
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
22
Which method is NOT part of the ListIterator interface?
A.hasPrevious
B.hasMore
C.add
D.hasNext
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
23
Select an appropriate expression to complete the following method, which is designed to visit the elements in theList and replace each occurrence of the string "hello" with the string "goodbye". Select an appropriate expression to complete the following method, which is designed to visit the elements in theList and replace each occurrence of the string hello with the string goodbye.   A.iterator.next() = goodbye; B.iterator.previous(goodbye); C.iterator.replace(hello, goodbye); D.iterator.set(goodbye);
A.iterator.next() = "goodbye";
B.iterator.previous("goodbye");
C.iterator.replace("hello", "goodbye");
D.iterator.set("goodbye");
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
24
When using a list iterator, on which condition will the IllegalStateException be thrown?
A.Calling next after calling previous.
B.Calling remove after calling previous.
C.Calling remove after calling remove.
D.Calling remove after calling next.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
25
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.3
B.2
C.4
D.1
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
26
Assume you have created a linked list named 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.getLast();
C.myList.pop();
D.myList.removeLast();
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
27
Consider the code snippet shown below.Assume that employeeNames is an instance of type LinkedList. Consider the code snippet shown below.Assume that employeeNames is an instance of type LinkedList<String>.   Which element(s) of employeeNames does this loop process? A.elements meeting a condition B.the most recently added elements C.no elements D.all elements Which element(s) of employeeNames does this loop process?
A.elements meeting a condition
B.the most recently added elements
C.no elements
D.all elements
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
28
A ____ 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.queue
B.priority queue
C.stack
D.linked list
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
29
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.randomly
D.doubly
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
30
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.insert("Harry");
B.myList.addFirst("Harry");
C.myList.add("Harry");
D.myList.put("Harry");
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
31
You use a(n) ____ to access elements inside a linked list.
A.queue
B.accessor
C.list iterator
D.index
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
32
When using the add method of the ListIterator to add an element to a linked list, which of the following statements is correct?
A.The new element is inserted before the iterator position, and a subsequent call to next would be unaffected.
B.The new element is inserted after the iterator position, and a subsequent call to next would return the new element.
C.The new element is inserted after the iterator position, and a subsequent call to previous would be unaffected.
D.The new element is inserted before the iterator position, and a subsequent call to next would return the new element.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
33
Consider the following code snippet: Consider the following code snippet:   What will this code print when it is executed? A.ghiabcdef B.defghiabc C.abcdefghi D.abcghidef What will this code print when it is executed?
A.ghiabcdef
B.defghiabc
C.abcdefghi
D.abcghidef
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
34
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.sorted access
C.arbitrary access
D.random access
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
35
What can a generic class be parameterized for?
A.methods
B.iterators
C.type
D.properties
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
36
When using a list iterator, on which condition will the IllegalStateException be thrown?
A.Calling remove after calling next.
B.Calling remove after calling add.
C.Calling add after calling previous.
D.Calling previous after calling previous.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
37
Which method is NOT part of the ListIterator interface?
A.next
B.delete
C.add
D.previous
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
38
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 remove after calling add.
C.Calling remove after calling previous.
D.Calling next when the iterator points to the last element.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
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. 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.   A.theList.next() != null B.iter.hasNext() C.theList.hasNext() D.iter.next() != null
A.theList.next() != null
B.iter.hasNext()
C.theList.hasNext()
D.iter.next() != null
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
40
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. 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.   A.(players.getFirst().equals(name)) B.(players[0].equals(name)) C.(players.contains(name)) D.(players.indexOf(name) == 1)
A.(players.getFirst().equals(name))
B.(players[0].equals(name))
C.(players.contains(name))
D.(players.indexOf(name) == 1)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following statements about manipulating objects in a map is NOT correct?
A.Use the remove method to remove a value from 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 add method to add a new element to the map.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
42
Assume that you have declared a set named mySet to hold String elements.Which of the following statements will correctly delete an element from mySet?
A.mySet.delete("apple");
B.mySet.remove("apple");
C.mySet.get("apple");
D.mySet.pop("apple");
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
43
Select an appropriate declaration to complete the following code segment, which is designed to read strings from standard input and display them in increasing alphabetical order, excluding any duplicates. Select an appropriate declaration to complete the following code segment, which is designed to read strings from standard input and display them in increasing alphabetical order, excluding any duplicates.   A.LinkedList<String> words = new LinkedList<>(); B.Set<String> words = new TreeSet<>(); C.Set<String> words = new Set<>(); D.Set<String> words = new HashSet<>();
A.LinkedList words = new LinkedList<>();
B.Set words = new TreeSet<>();
C.Set words = new Set<>();
D.Set words = new HashSet<>();
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
44
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.The value used to locate an element in a hash table is called a hash code.
D.You can add an element to a specific position within a hash table.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
45
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: 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:   A.String name = myMap.next(aKey); B.String name = MapKeySet.get(aKey); C.String name = myMap.get(aKey); D.String name = MapKeySet.next(aKey);
A.String name = myMap.next(aKey);
B.String name = MapKeySet.get(aKey);
C.String name = myMap.get(aKey);
D.String name = MapKeySet.next(aKey);
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
46
Consider the following code snippet: Consider the following code snippet:   What will be printed when this code is executed? A.[Mary, John, Robert, Sue] B.[John, Robert, Sue] C.[Mary, Robert, Sue] D.[Mary, John, Sue] What will be printed when this code is executed?
A.[Mary, John, Robert, Sue]
B.[John, Robert, Sue]
C.[Mary, Robert, Sue]
D.[Mary, John, Sue]
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
47
Assume that you have declared a map named myMap to hold String values with Integer keys.Which of the following statements will correctly delete an association from myMap?
A.myMap.remove(3);
B.myMap.remove("apple");
C.myMap.delete(3);
D.myMap.pop(3);
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
48
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 and II only
B.I only
C.II only
D.III only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
49
Which of the following statements about the TreeSet class is NOT correct?
A.Elements are stored in nodes.
B.Elements are arranged in linear fashion.
C.To use a TreeSet, it must be possible to compare the elements.
D.Elements are stored in sorted order.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
50
To create a TreeSet for a class of objects, the object class must ____.
A.implement the Set interface.
B.implement the Comparable interface.
C.create an iterator.
D.create a Comparator object.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following statements about manipulating objects in a set is correct?
A.If you try to remove an element that does not exist, an exception will occur.
B.If you try to add an element that already exists, an exception will occur.
C.A set iterator visits elements in the order in which the set implementation keeps them.
D.You can add an element at the position indicated by an iterator.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
52
Which of the following statements about manipulating objects in a map is NOT correct?
A.Use the put method to add an element to the map.
B.If you attempt to retrieve a value with a key that is not associated with any value, you will receive a null result.
C.Use the get method to retrieve a value associated with a key in the map.
D.You cannot change the value of an existing association in the map; you must delete it and re-add it with the new values.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
53
Select an appropriate expression to complete the following method, which is designed to return the number of elements in the parameter array numbers.If a value appears more than once, it should be counted exactly once. Select an appropriate expression to complete the following method, which is designed to return the number of elements in the parameter array numbers.If a value appears more than once, it should be counted exactly once.   A.return numbers.length - values.size(); B.return values.size(); C.return numbers.length; D.return values.length();
A.return numbers.length - values.size();
B.return values.size();
C.return numbers.length;
D.return values.length();
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
54
Your program uses a Map structure to store a number of user ids and corresponding email addresses.Although each user must have a unique id, two or more users can share the same email address.Assuming that all entries in the map have valid email addresses, select an appropriate expression to complete the method below, which adds a new id and email address to the map only if the id is not already in use.If the id is already in use, an error message is printed. Your program uses a Map structure to store a number of user ids and corresponding email addresses.Although each user must have a unique id, two or more users can share the same email address.Assuming that all entries in the map have valid email addresses, select an appropriate expression to complete the method below, which adds a new id and email address to the map only if the id is not already in use.If the id is already in use, an error message is printed.   A.!currentEmail.equals(email) B.currentEmail.equals(email) C.currentEmail != null D.currentEmail == null
A.!currentEmail.equals(email)
B.currentEmail.equals(email)
C.currentEmail != null
D.currentEmail == null
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
55
Assume that you have declared a map named myMap to hold String values with Integer keys.Which of the following statements will correctly retrieve the value associated with a key from myMap?
A.myMap.peek(3);
B.myMap.get("apple");
C.myMap.peek("apple");
D.myMap.get(3);
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
56
Which of the following statements about sets is correct?
A.Attempting to remove an element that is not in the set generates an exception.
B.You can add an element to a specific position within a set.
C.A set is a collection of unique elements organized for efficiency.
D.A set allows duplicate values.
Unlock Deck
Unlock for access to all 102 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.put(apple");
B.mySet.insert("apple");
C.mySet.add("apple");
D.mySet.push("apple");
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
58
Which of the following statements about manipulating objects in a set is correct?
A.A set iterator visits elements in the order in which they were added to the set.
B.You can remove an element at the position indicated by an iterator.
C.If you try to add an element that already exists, an exception will occur.
D.You can add an element at the position indicated by an iterator.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
59
Assume that you have declared a map named myMap to hold String values with Integer keys.Which of the following statements will correctly add an association into myMap?
A.myMap.insert(3, "apple");
B.myMap.add(3, "apple");
C.myMap.put(3, "apple");
D.myMap.push(3, "apple");
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
60
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: 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:   A.Map<String, String> mapKeySet = myMap.keySet(); B.Set<String, String> mapKeySet = myMap.keySet(); C.Set<String> mapKeySet = myMap.keySet(); D.Set<String> mapKeySet = myMap.getKeySet();
A.Map mapKeySet = myMap.keySet();
B.Set mapKeySet = myMap.keySet();
C.Set mapKeySet = myMap.keySet();
D.Set mapKeySet = myMap.getKeySet();
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
61
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 Map<>;
C.scores = new TreeMap<>;
D.scores = new TreeSet<>;
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
62
What operation is least efficient in a LinkedList?
A.Linear traversal step.
B.Random access of an element.
C.Adding an element in a position that has already been located.
D.Removing an element when the element's position has already been located.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
63
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.linked list
D.queue
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
64
You need to access values in objects by a key that is not part of the object.Which collection type should you use?
A.Hashtable
B.ArrayList
C.Map
D.Queue
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
65
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.getKeySet(); for (String key : keySet) {...}
B.Set keySet = myMap.keySet(); for (String key : keySet) {...}
C.Set keySet = myMap.keys(); for (String key : keySet) {...}
D.Set keySet = myMap.getKeys(); for (String key : keySet) {...}
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
66
You need to access values by an integer position.Which collection type should you use?
A.Queue
B.Map
C.Hashtable
D.ArrayList
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
67
You need to access values using a key, and the keys must be sorted.Which collection type should you use?
A.Queue
B.TreeMap
C.HashMap
D.ArrayList
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
68
Which of the following algorithms would be efficiently executed on an ArrayList?
A.remove first n / 2 elements from a list of n elements
B.add 1 element to the middle of a list with n elements
C.add n / 2 elements to a list with n / 2 elements
D.read n / 2 elements in random order from a list of n elements
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
69
Which of the following statements about hash functions is NOT correct?
A.Using a prime number as a hash multiplier will produce better hash codes.
B.If you supply your own hashCode method for a class, it must be compatible with that class's equals method.
C.A good hash function will minimize the number of objects that are assigned the same hash code.
D.A hash function produces a unique integer-valued hash code value for each distinct object.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
70
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.stack
B.queue
C.hash table
D.linked list
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
71
Assume that you have declared a stack named myStack to hold String elements.Which of the following statements will correctly add an element to myStack?
A.myStack.addItem("apple");
B.myStack.put("apple");
C.myStack.insert("apple");
D.myStack.push("apple");
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
72
Which data structure would best be used for storing a set of numbers and sorting them in ascending order?
A.queue
B.array
C.stack
D.list
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
73
You intend to use a hash set with your own object class.Which of the following statements is correct?
A.You cannot override the hashCode method in the Object class.
B.You can use the hash method of the Objects class to create your own hashCode method by combining the hash codes for the instance variables.
C.You can override the hash method for your class provided that it is compatible with its equals method.
D.Your class's hashCode method does not need to be compatible with its equals method.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
74
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.Hashtable
B.Map
C.Queue
D.Stack
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
75
Using the merge method of the Map interface, which statement correctly updates the wordCount map of type Map to count all of the occurrences of a word in a file?
A.wordCount.merge(word, 1, (k,v) -> v + 1);
B.word.merge(wordCount,(k,v) -> v + 1);
C.word.merge(wordCount, 1, (k,v) -> v + 1);
D.wordCount.merge(word,(k,v) -> v + 1);
Unlock Deck
Unlock for access to all 102 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.Queue
B.Map
C.Stack
D.Hashtable
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
77
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 HashTable<>;
B.scores = new HashMap<>;
C.scores = new TreeMap<>;
D.scores = new Map<>;
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
78
Using the merge method of the Map interface, which statement correctly updates the salesTotalByDept map of type Map to update the sales total for a dept by an integer sales value?
A.salesTotalByDept.merge(dept, sales,(d,s) -> s + 1);
B.sales.merge(salesTotalByDept, dept, (d,s) -> s + sales);
C.dept.merge(salesTotalByDept, sales, (d,s) -> s + sales);
D.salesTotalByDept.merge(dept, sales, (d,s) -> s + sales);
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
79
Which of the following statements about stacks is correct?
A.A stack implements random retrieval.
B.A stack implements last-in, first-out retrieval.
C.A stack stores elements in sorted order.
D.A stack implements first-in, first-out retrieval.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
80
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 102 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 102 flashcards in this deck.