Java Reference
In-Depth Information
public
public
void
void
remove
() {
throw
throw new
new
UnsupportedOperationException
(
"remove"
);
}
};
}
WARNING
This is just to show how the implementation of a linked list might work. Do not use the
simple
LinkList
class shown here; use the real one,
java.util.LinkedList
, shown in
action in the first example.
Mapping with Hashtable and HashMap
Problem
You need a one-way mapping from one data item to another.
Solution
Use a
HashMap
or the older
Hashtable
.
Discussion
HashMap
and the older
Hashtable
provide a one-way mapping from one set of object refer-
ences to another. They are completely general purpose. I've used them to map Swing push
buttons (see
Action Handling: Making Buttons Work
) to the URL to jump to when the button
is pushed, to map names to addresses, and to implement a simple in-memory cache in a web
server. You can map from anything to anything. In the following example, we map from
company names to addresses; the addresses here are
String
objects, but in real life they'd
probably be
Address
objects:
public
public class
class
HashMapDemo
HashMapDemo
{
public
public static
static
void
void
main
(
String
[]
argv
) {