Deck 16: Generic Collections
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/41
Play
Full screen (f)
Deck 16: Generic Collections
1
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.
A)int y = x;
B)Integer y = x;
C)Neither of the above.
D)Both of the above.
A
2
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.
A)stable.
B)lexicographical.
C)polymorphic.
D)implementation dependent.
C
3
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.
A)Comparable.
B)Comparator.
C)Compare.
D)Ordering.
A
4
Algorithm __________ randomly orders a List's elements.
A)randomShuffle.
B)randomPlacement.
C)fiftyTwoCardPickup.
D)shuffle.
A)randomShuffle.
B)randomPlacement.
C)fiftyTwoCardPickup.
D)shuffle.
Unlock Deck
Unlock for access to all 41 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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
6
LinkedList method listIterator returns a(n)__________.
A)Iterator.
B)List.
C)sub list.
D)bidirectional iterator.
A)Iterator.
B)List.
C)sub list.
D)bidirectional iterator.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
7
Iterator method __________ determines whether the Collection contains more elements.
A)hasNext.
B)next.
C)contains.
D)containsNext.
A)hasNext.
B)next.
C)contains.
D)containsNext.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
8
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
9
Collections method ___________ returns a Comparator object that orders the collection's elements in reverse order.
A)rotate.
B)shuffle.
C)reverse.
D)reverseOrder.
A)rotate.
B)shuffle.
C)reverse.
D)reverseOrder.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following does not implement interface List?
A)ArrayList.
B)LinkedList.
C)Vector.
D)ListIterator.
A)ArrayList.
B)LinkedList.
C)Vector.
D)ListIterator.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
11
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.
A)a positive int value.
B)zero.
C)a negative int value.
D)a String.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
12
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
13
Java supports type inferencing with the <> notation in statements that declare and create generic type variables and objects.For example,the following line:
List list = new ArrayList();
Can be written as:
A)List<> list = new ArrayList<>();
B)List<> list = new ArrayList();
C)List list = new ArrayList<>();
D)List list = new ArrayList();
List
Can be written as:
A)List<> list = new ArrayList<>();
B)List<> list = new ArrayList
C)List
D)List
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
14
Interface Collection contains __________ operations (i.e.,operations performed on the entire collection).
A)aggregate.
B)composite.
C)integral.
D)bulk.
A)aggregate.
B)composite.
C)integral.
D)bulk.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
15
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
16
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
17
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.
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.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
18
A(n)__________ allows a program to walk through the collection and remove elements from the collection.
A)Set.
B)Queue.
C)Iterator.
D)List.
A)Set.
B)Queue.
C)Iterator.
D)List.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
19
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.
A)java.util.
B)javax.swing.
C)java.collections.
D)java.collection.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
20
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
21
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.
A)abstract.
B)concrete.
C)structured.
D)unstructured.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
22
__________ methods enable a program to view a portion of a collection.
A)Focus-view.
B)Range-view.
C)Delimiter-view.
D)Subset-view.
A)Focus-view.
B)Range-view.
C)Delimiter-view.
D)Subset-view.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
23
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.
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 41 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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
25
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
26
Class Collections provides algorithms for reversing,filling and copying ________.
A)Lists.
B)Collections.
C)Arrays.
D)Stacks.
A)Lists.
B)Collections.
C)Arrays.
D)Stacks.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
27
Map method ________ is used to determine whether a map contains a mapping for the specified key.
A)containsKey
B)hasKey
C)containsMapping
D)hasMapping
A)containsKey
B)hasKey
C)containsMapping
D)hasMapping
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
28
If no elements are in the Stack,method pop throws an __________.
A)OutOfMemoryError.
B)OutOfMemoryException.
C)EmptyStackError.
D)EmptyStackException.
A)OutOfMemoryError.
B)OutOfMemoryException.
C)EmptyStackError.
D)EmptyStackException.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
29
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
30
Stack method __________ looks at the top element of a stack without removing that element.
A)glance.
B)peek.
C)look.
D)sample.
A)glance.
B)peek.
C)look.
D)sample.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
31
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
32
A Properties object is a __________ Hashtable object.
A)transient.
B)persistent.
C)polymorphic.
D)protected.
A)transient.
B)persistent.
C)polymorphic.
D)protected.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
33
Objects of many classes can now be output and input with Java's object __________.
A)encapsulation.
B)overloading.
C)serialization.
D)reflection.
A)encapsulation.
B)overloading.
C)serialization.
D)reflection.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
34
If the desired Object is not found,binarySearch returns __________.
A)a positive value
B)zero
C)a negative value
D)an ObjectNotFoundError.
A)a positive value
B)zero
C)a negative value
D)an ObjectNotFoundError.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
35
Method shuffle is a member of __________.
A)class Arrays.
B)class Collections.
C)interface Collection.
D)Interface List.
A)class Arrays.
B)class Collections.
C)interface Collection.
D)Interface List.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
36
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.
A)many-to-many.
B)many-to-one.
C)one-to-many.
D)one-to-one.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
37
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.
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 41 flashcards in this deck.
Unlock Deck
k this deck
38
Collections method __________ returns true if two Collections have no elements in common.
A)shuffle.
B)contains.
C)hasCommon.
D)disjoint.
A)shuffle.
B)contains.
C)hasCommon.
D)disjoint.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
39
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.
A)least,greatest.
B)smallest,largest.
C)first,last.
D)min,max.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
40
PriorityQueue method __________ inserts an element at the appropriate location in the queue.
A)offer.
B)push.
C)poll.
D)peek.
A)offer.
B)push.
C)poll.
D)peek.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following is not an abstract implementation provided by the collections framework?
A)AbstractCollection.
B)AbstractTree.
C)AbstractMap.
D)AbstractList.
A)AbstractCollection.
B)AbstractTree.
C)AbstractMap.
D)AbstractList.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck