Java Reference
In-Depth Information
c) A Map can contain duplicate keys.
d) A LinkedList can contain duplicate values.
e) Collections is an interface .
f) Iterator s can remove elements.
g)
With hashing, as the load factor increases, the chance of collisions decreases.
h)
A PriorityQueue permits null elements.
Answers to Self-Review Exercises
16.1 a) Iterator . b) index. c) autoboxing. d) ArrayList , Vector . e) double. f) unmodifiable
wrapper. g) auto-unboxing. h) disjoint .
16.2 a) False. Autoboxing occurs when adding a primitive type to a collection, which means the
primitive type is converted to its corresponding type-wrapper class.
b)
False. A Set cannot contain duplicate values.
c)
False. A Map cannot contain duplicate keys.
d)
True.
e)
False. Collections is a class ; Collection is an interface .
f)
True.
g)
False. As the load factor increases, fewer slots are available relative to the total number
of slots, so the chance of a collision increases.
h)
False. Attempting to insert a null element causes a NullPointerException .
Execises
16.3 Define each of the following terms:
a) Collection
b) Collections
c) Comparator
d) List
e) load factor
f) collision
g) space/time trade-off in hashing
h) HashMap
16.4 Explain briefly the operation of each of the following methods of class Vector :
a) add
b) set
c) remove
d) removeAllElements
e) removeElementAt
f) firstElement
g) lastElement
h) contains
i) indexOf
j) size
k) capacity
16.5 Explain why inserting additional elements into a Vector object whose current size is less
than its capacity is a relatively fast operation and why inserting additional elements into a Vector
object whose current size is at capacity is a relatively slow operation.
16.6 By extending class Vector , Java's designers were able to create class Stack quickly. What are
the negative aspects of this use of inheritance, particularly for class Stack ?
Search WWH ::




Custom Search