Deck 16: Generic Collections

Full screen (f)
exit full mode
Question
Interface Collection contains __________ operations (i.e., operations performed on the entire collection).

A) aggregate.
B) composite.
C) integral.
D) bulk.
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following performs an unboxing conversion?
Assume x refers to an Integer object.

A) int y = x;
B) Integer y = x;
C) Neither of the above.
D) Both of the above.
Question
Which statement is false?

A) A collection is an object that can hold references to other objects.
B) The collection interfaces declare the operations that can be performed on each type of collection.
C) Collections discourage software reuse because they are non-portable.
D) Collections are carefully constructed for rapid execution and efficient use of memory.
Question
Comparator method compare should return ________ if the first argument is greater than the second argument.

A) a positive int value.
B) zero.
C) a negative int value.
D) a String.
Question
Which statement is false?

A) A List is a Collection.
B) A List cannot contain duplicate elements.
C) A List is sometimes called a sequence.
D) Lists use zero-based indices.
Question
Which statement is false?

A) Each primitive type has a corresponding type-wrapper class.
B) The type-wrapper classes enable you to manipulate primitive-type values as objects.
C) Type-wrapper classes are final, so you cannot extend them.
D) The methods for primitive types correspond to the methods for the corresponding type-wrapper classes.
Question
LinkedList method listIterator returns a(n) __________.

A) Iterator.
B) List.
C) sub list.
D) bidirectional iterator.
Question
Method shuffle is a member of __________.

A) class Arrays.
B) class Collections.
C) interface Collection.
D) Interface List.
Question
Collections method sort that accepts a List as an argument. It sorts the List elements, which must implement the __________ interface.

A) Comparable.
B) Comparator.
C) Compare.
D) Ordering.
Question
The collections framework algorithms are __________, i.e., each of these algorithms can operate on objects that implement specified interfaces without concern for the underlying implementations.

A) stable.
B) lexicographical.
C) polymorphic.
D) implementation dependent.
Question
Which of the following performs a boxing conversion?

A) int x = 7;
B) Integer x = 7;
C) Neither of the above.
D) Both of the above.
Question
Java supports type inferencing with the <> notation in statements that declare and create generic type variables and objects. For example, the following line: List<String> list = new ArrayList<String>();
Can be written as:

A) List<> list = new ArrayList<>();
B) List<> list = new ArrayList<String>();
C) List<String> list = new ArrayList<>();
D) List<String> list = new ArrayList();
Question
Which statement is false?

A) A ListIterator accesses the elements of a List.
B) Class ArrayList is a fixed-size array.
C) A LinkedList is a linked list implementation of a List.
D) ArrayLists execute faster than Vectors because they are not thread safe.
Question
Algorithm __________ randomly orders a List's elements.

A) randomShuffle.
B) randomPlacement.
C) fiftyTwoCardPickup.
D) shuffle.
Question
Which of these is not an example of a "real-life" collection?

A) The cards you hold in a card game.
B) Your favorite songs stored in your computer.
C) The players on a soccer team.
D) The number of pages in a book.
Question
A(n)__________ allows a program to walk through the collection and remove elements from the collection.

A) Set.
B) Queue.
C) Iterator.
D) List.
Question
Which statement is false?

A) When a List is backed by an array, any modifications made through the List view change the array.
B) When a List is backed by an array, any modifications made to the array change the List view.
C) The only operation permitted on the view returned by Arrays method asList is delete, which deletes the value from the view and the backing array.
D) Adding elements to the view returned by Arrays method asList results in an UnsupportedOperationException.
Question
The classes and interfaces which comprise the collections framework are members of package ________.

A) java.util.
B) javax.swing.
C) java.collections.
D) java.collection.
Question
Collections method ___________ returns a Comparator object that orders the collection's elements in reverse order.

A) rotate.
B) shuffle.
C) reverse.
D) reverseOrder.
Question
Iterator method __________ determines whether the Collection contains more elements.

A) hasNext.
B) next.
C) contains.
D) containsNext.
Question
__________ methods enable a program to view a portion of a collection.

A) Focus-view.
B) Range-view.
C) Delimiter-view.
D) Subset-view.
Question
The collections framework provides various __________ collection interfaces from which the programmer can quickly "flesh out" complete customized implementations.

A) abstract.
B) concrete.
C) structured.
D) unstructured.
Question
Class Collections provides algorithms for reversing, filling and copying ________.

A) Lists.
B) Collections.
C) Arrays.
D) Stacks.
Question
Which statement is false?

A) The Collections API provides a set of public static methods for converting collections to unmodifiable versions.
B) Unmodifable wrappers throw ModificationExceptions if attempts are made to modify the collection.
C) You can use an unmodifiable wrapper to create a collection that offers read-only access to others while allowing read-write access to yourself.
D) You can create the kind of collection mentioned in part (c) simply by giving others a reference to the unmodifiable wrapper while you also retain a reference to the wrapped collection itself.
Question
Which of the following is not an abstract implementation provided by the collections framework?

A) AbstractCollection.
B) AbstractTree.
C) AbstractMap.
D) AbstractList.
Question
Which statement is false?

A) Java does not guarantee which item will be found first when a binarySearch is performed on a List containing multiple elements equivalent to the search key.
B) If the search key is found, method binarySearch returns the List index (position relative to 1) of the element containing the search key.
C) The binary search algorithm is fast.
D) Method binarySearch takes a List as the first argument.
Question
PriorityQueue method __________ inserts an element at the appropriate location in the queue.

A) offer.
B) push.
C) poll.
D) peek.
Question
Collections method __________ returns true if two Collections have no elements in common.

A) shuffle.
B) contains.
C) hasCommon.
D) disjoint.
Question
Which statement is false?

A) SortedSet extends Set.
B) Class SortedSet implements TreeSet.
C) When a HashSet is constructed, it removes any duplicates in the Collection.
D) By definition, a Set object does not contain any duplicates.
Question
Which statement is false?

A) All built-in collections are synchronized.
B) Concurrent access to a Collection by multiple threads could cause indeterminate results or fatal errors.
C) To prevent potential threading problems, synchronization wrappers are used around collection classes that might be accessed by multiple threads.
D) A synchronization wrapper class receives method calls, adds some functionality for thread safety and then delegates the calls to the wrapped class.
Question
If the desired Object is not found, binarySearch returns __________.

A) a positive value
B) zero
C) a negative value
D) an ObjectNotFoundError.
Question
To find the smallest and largest element of a Collection, use Collections methods _________ and __________.

A) least, greatest.
B) smallest, largest.
C) first, last.
D) min, max.
Question
Maps allocate keys to values and cannot contain duplicate keys, i.e., the key-to-value mapping is a __________ mapping.

A) many-to-many.
B) many-to-one.
C) one-to-many.
D) one-to-one.
Question
Which statement about hashing is false?

A) Hashing facilitates high-speed storing and retrieval of data.
B) Two different data items can hash to the same cell; this is called a collision.
C) A load factor of 0.5 usually results in good hashing performance, but less efficient utilization of memory.
D) A load factor of 1.0 usually results in good hashing performance, but less efficient utilization of memory.
Question
Map method ________ is used to determine whether a map contains a mapping for the specified key.

A) containsKey
B) hasKey
C) containsMapping
D) hasMapping
Question
Which statement is false?

A) Queue is a new collection interface introduced in J2SE 5.0.
B) Queue and PriorityQueue are included in the java.util package.
C) PriorityQueue orders elements in increasing order, so that smallest value will be the first element removed from PriorityQueue.
D) Queue extends interface Collection.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/36
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 16: Generic Collections
1
Interface Collection contains __________ operations (i.e., operations performed on the entire collection).

A) aggregate.
B) composite.
C) integral.
D) bulk.
D
2
Which of the following performs an unboxing conversion?
Assume x refers to an Integer object.

A) int y = x;
B) Integer y = x;
C) Neither of the above.
D) Both of the above.
int y = x;
3
Which statement is false?

A) A collection is an object that can hold references to other objects.
B) The collection interfaces declare the operations that can be performed on each type of collection.
C) Collections discourage software reuse because they are non-portable.
D) Collections are carefully constructed for rapid execution and efficient use of memory.
C
4
Comparator method compare should return ________ if the first argument is greater than the second argument.

A) a positive int value.
B) zero.
C) a negative int value.
D) a String.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
5
Which statement is false?

A) A List is a Collection.
B) A List cannot contain duplicate elements.
C) A List is sometimes called a sequence.
D) Lists use zero-based indices.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
6
Which statement is false?

A) Each primitive type has a corresponding type-wrapper class.
B) The type-wrapper classes enable you to manipulate primitive-type values as objects.
C) Type-wrapper classes are final, so you cannot extend them.
D) The methods for primitive types correspond to the methods for the corresponding type-wrapper classes.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
7
LinkedList method listIterator returns a(n) __________.

A) Iterator.
B) List.
C) sub list.
D) bidirectional iterator.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
8
Method shuffle is a member of __________.

A) class Arrays.
B) class Collections.
C) interface Collection.
D) Interface List.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
9
Collections method sort that accepts a List as an argument. It sorts the List elements, which must implement the __________ interface.

A) Comparable.
B) Comparator.
C) Compare.
D) Ordering.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
10
The collections framework algorithms are __________, i.e., each of these algorithms can operate on objects that implement specified interfaces without concern for the underlying implementations.

A) stable.
B) lexicographical.
C) polymorphic.
D) implementation dependent.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following performs a boxing conversion?

A) int x = 7;
B) Integer x = 7;
C) Neither of the above.
D) Both of the above.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
12
Java supports type inferencing with the <> notation in statements that declare and create generic type variables and objects. For example, the following line: List<String> list = new ArrayList<String>();
Can be written as:

A) List<> list = new ArrayList<>();
B) List<> list = new ArrayList<String>();
C) List<String> list = new ArrayList<>();
D) List<String> list = new ArrayList();
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
13
Which statement is false?

A) A ListIterator accesses the elements of a List.
B) Class ArrayList is a fixed-size array.
C) A LinkedList is a linked list implementation of a List.
D) ArrayLists execute faster than Vectors because they are not thread safe.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
14
Algorithm __________ randomly orders a List's elements.

A) randomShuffle.
B) randomPlacement.
C) fiftyTwoCardPickup.
D) shuffle.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
15
Which of these is not an example of a "real-life" collection?

A) The cards you hold in a card game.
B) Your favorite songs stored in your computer.
C) The players on a soccer team.
D) The number of pages in a book.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
16
A(n)__________ allows a program to walk through the collection and remove elements from the collection.

A) Set.
B) Queue.
C) Iterator.
D) List.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
17
Which statement is false?

A) When a List is backed by an array, any modifications made through the List view change the array.
B) When a List is backed by an array, any modifications made to the array change the List view.
C) The only operation permitted on the view returned by Arrays method asList is delete, which deletes the value from the view and the backing array.
D) Adding elements to the view returned by Arrays method asList results in an UnsupportedOperationException.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
18
The classes and interfaces which comprise the collections framework are members of package ________.

A) java.util.
B) javax.swing.
C) java.collections.
D) java.collection.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
19
Collections method ___________ returns a Comparator object that orders the collection's elements in reverse order.

A) rotate.
B) shuffle.
C) reverse.
D) reverseOrder.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
20
Iterator method __________ determines whether the Collection contains more elements.

A) hasNext.
B) next.
C) contains.
D) containsNext.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
21
__________ methods enable a program to view a portion of a collection.

A) Focus-view.
B) Range-view.
C) Delimiter-view.
D) Subset-view.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
22
The collections framework provides various __________ collection interfaces from which the programmer can quickly "flesh out" complete customized implementations.

A) abstract.
B) concrete.
C) structured.
D) unstructured.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
23
Class Collections provides algorithms for reversing, filling and copying ________.

A) Lists.
B) Collections.
C) Arrays.
D) Stacks.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
24
Which statement is false?

A) The Collections API provides a set of public static methods for converting collections to unmodifiable versions.
B) Unmodifable wrappers throw ModificationExceptions if attempts are made to modify the collection.
C) You can use an unmodifiable wrapper to create a collection that offers read-only access to others while allowing read-write access to yourself.
D) You can create the kind of collection mentioned in part (c) simply by giving others a reference to the unmodifiable wrapper while you also retain a reference to the wrapped collection itself.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following is not an abstract implementation provided by the collections framework?

A) AbstractCollection.
B) AbstractTree.
C) AbstractMap.
D) AbstractList.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
26
Which statement is false?

A) Java does not guarantee which item will be found first when a binarySearch is performed on a List containing multiple elements equivalent to the search key.
B) If the search key is found, method binarySearch returns the List index (position relative to 1) of the element containing the search key.
C) The binary search algorithm is fast.
D) Method binarySearch takes a List as the first argument.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
27
PriorityQueue method __________ inserts an element at the appropriate location in the queue.

A) offer.
B) push.
C) poll.
D) peek.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
28
Collections method __________ returns true if two Collections have no elements in common.

A) shuffle.
B) contains.
C) hasCommon.
D) disjoint.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
29
Which statement is false?

A) SortedSet extends Set.
B) Class SortedSet implements TreeSet.
C) When a HashSet is constructed, it removes any duplicates in the Collection.
D) By definition, a Set object does not contain any duplicates.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
30
Which statement is false?

A) All built-in collections are synchronized.
B) Concurrent access to a Collection by multiple threads could cause indeterminate results or fatal errors.
C) To prevent potential threading problems, synchronization wrappers are used around collection classes that might be accessed by multiple threads.
D) A synchronization wrapper class receives method calls, adds some functionality for thread safety and then delegates the calls to the wrapped class.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
31
If the desired Object is not found, binarySearch returns __________.

A) a positive value
B) zero
C) a negative value
D) an ObjectNotFoundError.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
32
To find the smallest and largest element of a Collection, use Collections methods _________ and __________.

A) least, greatest.
B) smallest, largest.
C) first, last.
D) min, max.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
33
Maps allocate keys to values and cannot contain duplicate keys, i.e., the key-to-value mapping is a __________ mapping.

A) many-to-many.
B) many-to-one.
C) one-to-many.
D) one-to-one.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
34
Which statement about hashing is false?

A) Hashing facilitates high-speed storing and retrieval of data.
B) Two different data items can hash to the same cell; this is called a collision.
C) A load factor of 0.5 usually results in good hashing performance, but less efficient utilization of memory.
D) A load factor of 1.0 usually results in good hashing performance, but less efficient utilization of memory.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
35
Map method ________ is used to determine whether a map contains a mapping for the specified key.

A) containsKey
B) hasKey
C) containsMapping
D) hasMapping
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
36
Which statement is false?

A) Queue is a new collection interface introduced in J2SE 5.0.
B) Queue and PriorityQueue are included in the java.util package.
C) PriorityQueue orders elements in increasing order, so that smallest value will be the first element removed from PriorityQueue.
D) Queue extends interface Collection.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 36 flashcards in this deck.