Java Reference
In-Depth Information
1
package weiss.util;
2
3
/**
4
* Map interface.
5
* A map stores key/value pairs.
6
* In our implementations, duplicate keys are not allowed.
7
*/
8
public interface Map<KeyType,ValueType> extends java.io.Serializable
9
{
10
/**
11
* Returns the number of keys in this map.
12
*/
13
int size( );
14
15
/**
16
* Tests if this map is empty.
17
*/
18
boolean isEmpty( );
19
20
/**
21
* Tests if this map contains a given key.
22
*/
23
boolean containsKey( KeyType key );
24
25
/**
26
* Returns the value that matches the key or null
27
* if the key is not found. Since null values are allowed,
28
* checking if the return value is null may not be a
29
* safe way to ascertain if the key is present in the map.
30
*/
31
ValueType get( KeyType key );
32
33
/**
34
* Adds the key/value pair to the map, overriding the
35
* original value if the key was already present.
36
* Returns the old value associated with the key, or
37
* null if the key was not present prior to this call.
38
*/
39
ValueType put( KeyType key, ValueType value );
40
41
/**
42
* Removes the key and its value from the map.
43
* Returns the previous value associated with the key,
44
* or null if the key was not present prior to this call.
45
*/
46
ValueType remove( KeyType key );
figure 6.36
A sample
Map
interface (part 1)
Search WWH ::
Custom Search