Programming Languages Chapter 16 Class Collections Provides Algorithms For Reversing

subject Type Homework Help
subject Pages 7
subject Words 1890
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 16 Generic Collections
16.1 Q1: 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.
16.2 Q1: 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.
16.2 Q2: 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.
16.3 Q1: 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.
16.4 Q1: 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.
16.4 Q2: 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.
page-pf2
16.5 Q1: A(n) __________ allows a program to walk through the collection and remove elements from the
collection.
a. Set.
b. Queue.
c. Iterator.
d. List.
16.5 Q2: Interface Collection contains __________ operations (i.e., operations performed on the entire
collection).
a. aggregate.
b. composite.
c. integral.
d. bulk.
16.6 Q1: 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.
16.6 Q2: Which of the following does not implement interface List?
a. ArrayList.
b. LinkedList.
c. Vector.
d. ListIterator.
16.6.1 Q1: 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.
16.6.1 Q2: Iterator method __________ determines whether the Collection contains more elements.
a. hasNext.
b. next.
c. contains.
d. containsNext.
16.6.1 Q3: 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>();
page-pf3
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();
16.6.2 Q1: LinkedList method listIterator returns a(n) __________.
a. Iterator.
b. List.
c. sub list.
d. bidirectional iterator.
16.6.2 Q2: 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.
16.7 Q1: 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.
16.7.1 Q1: 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.
16.7.1 Q2: Collections method ___________ returns a Comparator object that orders the collection’s
elements in reverse order.
a. rotate.
b. shuffle.
c. reverse.
d. reverseOrder.
page-pf4
16.7.1 Q3: 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.
16.7.2 Q1: Algorithm __________ randomly orders a List's elements.
a. randomShuffle.
b. randomPlacement.
c. fiftyTwoCardPickup.
d. shuffle.
16.7.2 Q2: Method shuffle is a member of __________.
a. class Arrays.
b. class Collections.
c. interface Collection.
d. Interface List.
16.7.3 Q1: Class Collections provides algorithms for reversing, filling and copying ________.
a. Lists.
b. Collections.
c. Arrays.
d. Stacks.
16.7.3 Q2: 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.
16.7.4 Q1: If the desired Object is not found, binarySearch returns __________.
a. a positive value
b. zero
c. a negative value
d. an ObjectNotFoundError.
16.7.4 Q2: 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.
page-pf5
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.
16.7.5 Q1: Collections method __________ returns true if two Collections have no elements in
common.
a. shuffle.
b. contains.
c. hasCommon.
d. disjoint.
16.8 Q1: Stack method __________ looks at the top element of a stack without removing that element.
a. glance.
b. peek.
c. look.
d. sample.
16.8 Q2: If no elements are in the Stack, method pop throws an __________.
a. OutOfMemoryError.
b. OutOfMemoryException.
c. EmptyStackError.
d. EmptyStackException.
16.9 Q1: 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.
16.9 Q2: PriorityQueue method __________ inserts an element at the appropriate location in the queue.
a. offer.
b. push.
c. poll.
d. peek.
16.10 Q1: __________ methods enable a program to view a portion of a collection.
page-pf6
a. Focus-view.
b. Range-view.
c. Delimiter-view.
d. Subset-view.
16.10 Q2: 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.
16.11 Q1: 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.
16.11 Q2: 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.
16.11 Q3: Map method ________ is used to determine whether a map contains a mapping for the specified
key. a. containsKey
b. hasKey
c. containsMapping
d. hasMapping
16.12 Q1: A Properties object is a __________ Hashtable object.
a. transient.
b. persistent.
c. polymorphic.
d. protected.
16.12 Q2: Objects of many classes can now be output and input with Java's object __________.
a. encapsulation.
b. overloading.
c. serialization.
page-pf7
d. reflection.
16.13 Q1: 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.
16.14 Q1: 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.
16.15 Q1: 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.
16.15 Q2: Which of the following is not an abstract implementation provided by the collections
framework?
a. AbstractCollection.
b. AbstractTree.
c. AbstractMap.
d. AbstractList.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.