Self-Review Exercises
16.1 Fill in the blanks in each of the following statements:
a) A(n) Iterator is used to iterate through a collection and can remove elements from the collection during the iteration.
b) An element in a List can be accessed by using the element’s index .
c) Assuming that myArray contains references to Double objects, auto-boxing occurs when the statement "myArray[0] = 1.25;" executes.
d) Java classes ArrayList and Vector provide the capabilities of arraylike data structures that can resize themselves dynamically.
e) If you do not specify a capacity increment, the system will double the size of the Vector each time additional capacity is needed.
f) You can use a(n) unmodifiable wrapper to create a collection that offers only read-only access to others
while allowing read–write access to yourself.
g) Assuming that myArray contains references to Double objects, auto-unboxing occurs when the statement "double number = myArray[0];" executes.
h) Collections algorithm disjoint determines if two collections have elements in common.
16.2 Determine whether each statement is true or false. If false, explain why.
a) Values of primitive types may be stored directly in a collection. (F)
b) A Set can contain duplicate values. (F)
c) A Map can contain duplicate keys. (F)
d) A LinkedList can contain duplicate values. (T)
e) Collections is an interface. (F)
f) Iterators can remove elements. (T)
g) With hashing, as the load factor increases, the chance of collisions decreases. (T)
h) A PriorityQueue permits null elements. (F)