Self-Assessment Exercises
Chapter 14:
Map Collections and Custom Collection Classes
1.
Which of the following is true about maps?
a.
A map matches a value to a key.
b.
The Java library provides two abstract implementations of the map, the
TreeMap
and the
HashMap
.
c.
The
keySet()
method returns a set of keys in the map.
d.
All of the above
2.
Which of the following is NOT true about the comparison between the
HashMap
and
TreeMap
classes?
a.
In a
HashMap
, the values are hashed.
b.
Retrievals are somewhat more efficient in a
HashMap
.
c.
The difference between them is how they manage keys.
d.
The
TreeMap
class builds an ordering of the keys.
3.
What happens when you try to create a duplicate key in a map with a
put()
call?
a.
A
DuplicateKey
exception is thrown.
b.
put()
returns
false
.
c.
put()
returns
null
.
d.
The value associated with the key is replaced.
4.
A properly designed custom collection class should ________.
a.
use the
Listable
interface provided by the Java collection framework
b.
implement a
compare()
method
c.
maintain the elements in sorted order
d.
None of the above
5.
What is meant by the phrase “encapsulation of responsibility”?
a.
A student will be graded on how well their program works.
b.
Each class is responsible for only one thing. Other responsibilities are delegated.
c.
Each class is responsible for understanding the semantics of other classes.
d.
The Java Virtual Machine (JVM) is responsible for providing “system functions.”