Chapter 16: Generic Collections

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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.

b. Class SortedSet implements TreeSet.

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.

b. Integer x = 7;

Class Collections provides algorithms for reversing, filling and copying ________. a. Lists. b. Collections. c. Arrays. d. Stacks.

a. Lists.

Objects of many classes can now be output and input with Java's object __________. a. encapsulation. b. overloading. c. serialization. d. reflection.

c. serialization

LinkedList method listIterator returns a(n) __________. a. Iterator. b. List. c. sub list. d. bidirectional iterator.

d. bidirectional iterator.

Interface Collection contains __________ operations (i.e., operations performed on the entire collection). a. aggregate. b. composite. c. integral. d. bulk.

d. bulk

Collections method __________ returns true if two Collections have no elements in common. a. shuffle. b. contains. c. hasCommon. d. disjoint.

d. disjoint

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.

d. the number of pages in a book.

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();

c. List<String> list = new ArrayList<>();

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.

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

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.

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

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

Iterator method __________ determines whether the Collection contains more elements. a. hasNext. b. next. c. contains. d. containsNext.

a. hasNext

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;

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

PriorityQueue method __________ inserts an element at the appropriate location in the queue. a. offer. b. push. c. poll. d. peek.

a. offer

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.

b. A list cannot contain duplicate elements

Which of the following is not an abstract implementation provided by the collections framework? a. AbstractCollection. b. AbstractTree. c. AbstractMap. d. AbstractList.

b. AbstractTree

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.

b. Class ArrayList is a fixed-size array.

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.

b. If the search key is found, method binarySearch returns the List index (position relative to 1) of the element containing the search key.

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.

c. PriorityQueue orders elements in increasing order, so that the smallest value will be the first element removed from PriorityQueue

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.

c. The only operation permitted on the view returned by Arrays method asList is delete, whic deletes the values from the view and the backing array.

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.

c. polymorphic

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.

d. A load factor of 1.0 usually results in good hashing performance, but less efficient utilization of memory.

__________ methods enable a program to view a portion of a collection. a. Focus-view. b. Range-view. c. Delimiter-view. d. Subset-view.

b. Range-view.

Collections method ___________ returns a Comparator object that orders the collection's elements in reverse order. a. rotate. b. shuffle. c. reverse. d. reverseOrder.

d. reverseOrder

Algorithm __________ randomly orders a List's elements. a. randomShuffle. b. randomPlacement. c. fiftyTwoCardPickup. d. shuffle.

d. shuffle

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.

b. Unmodifiable wrappers throw ModificationExceptions if attempts are made to modify the collection.

Method shuffle is a member of __________. a. class Arrays. b. class Collections. c. interface Collection. d. Interface List.

b. class Collections

Stack method __________ looks at the top element of a stack without removing that element. a. glance. b. peek. c. look. d. sample.

b. peek

A Properties object is a __________ Hashtable object. a. transient. b. persistent. c. polymorphic. d. protected.

b. persistent

If the desired Object is not found, binarySearch returns __________. a. a positive value b. zero c. a negative value d. an ObjectNotFoundError.

c. A negative value

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. Collection discourage software reuse because they are non portable.

A(n) __________ allows a program to walk through the collection and remove elements from the collection. a. Set. b. Queue. c. Iterator. d. List.

c. Iterator

If no elements are in the Stack, method pop throws an __________. a. OutOfMemoryError. b. OutOfMemoryException. c. EmptyStackError. d. EmptyStackException.

d. EmptyStackException

Which of the following does not implement interface List? a. ArrayList. b. LinkedList. c. Vector. d. ListIterator.

d. ListIterator

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.

d. The methods for primitive types correspond to the methods for the corresponding type-wrapper classes. Primitive types do not have methods.

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.

d. min, max.

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.

d. one-to-one


Set pelajaran terkait

Document A: Declaration of Independence (Focus on the Principle of EQUALITY)

View Set

Chapter 14: Arterial Puncture Procedures

View Set

Chapter 7 - Promulgated Addenda, Notices and Other Forms: Practice Questions

View Set

AP World History Chapter 28 Key Terms

View Set

PSY 160: Chapter 1: Foundations of Psychiatric-Mental Health Nursing - ML5

View Set