Java Reference
In-Depth Information
•
HashMap
takes two type arguments—the type of key and the type of value.
•
HashMap
method
put
(p. 717) adds a key-value pair to a
HashMap
. Method
get
(p. 717) locates the
value associated with the specified key. Method
isEmpty
(p. 718) determines if the map is empty.
•
HashMap
method
keySet
(p. 718) returns a set of the keys.
Map
method
size
(p. 718) returns the
number of key-value pairs in the
Map
.
• Interface
SortedMap
(p. 714) extends
Map
and represents a map that maintains its keys in sorted
order. Class
TreeMap
implements
SortedMap
.
Section 16.12
Properties
Class
•A
Properties
object (p. 718) is a persistent subclass of
Hashtable
.
•The
Properties
no-argument constructor creates an empty
Properties
table. An overloaded
constructor receives a
Properties
object containing default property values.
•
Properties
method
setProperty
(p. 718) specifies the value associated with its key argument.
Method
getProperty
(p. 718) locates the value of the key specified as an argument. Method
store
(p. 720) saves the contents of a
Properties
object to specified
OutputStream
. Method
load
(p. 721) restores the contents of a
Properties
object from the specified
InputStream
.
Section 16.13 Synchronized Collections
• Collections from the collections framework are unsynchronized. Synchronization wrappers
(p. 721) are provided for collections that can be accessed by multiple threads simultaneously.
Section 16.14 Unmodifiable Collections
• Unmodifiable collection wrappers (p. 721) throw
UnsupportedOperationException
s (p. 694) if
attempts are made to modify the collection.
Section 16.15 Abstract Implementations
• The collections framework provides various abstract implementations of collection interfaces
from which you can quickly flesh out complete customized implementations.
Self-Review Exercises
16.1
Fill in the blanks in each of the following statements:
a)
A(n) 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
.
c)
Assuming that
myArray
contains references to
Double
objects,
occurs when the
statement "
myArray[0
]
= 1.25;
" executes.
d)
Java classes and provide the capabilities of arraylike data structures
that can resize themselves dynamically.
e)
If you do not specify a capacity increment, the system will
the size of the
Vec-
tor
each time additional capacity is needed.
f)
You can use a(n) to create a collection that offers only read-only access to oth-
ers while allowing read-write access to yourself.
g)
Assuming that
myArray
contains references to
Double
objects,
occurs when the
statement "
double
number
=
myArray[0
]
;
" executes.
h)
Collections
algorithm
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.
b)
A
Set
can contain duplicate values.