Contents | Prev | Next | Index

21.4 The Class java.util.Dictionary

A Dictionary is an object that associates elements with keys. Every key and every element is an object. In any one Dictionary, every key is associated at most one element. Given a Dictionary and a key, the associated element can be looked up.

public abstract class Dictionary {
	abstract public int size();
	abstract public boolean isEmpty();
	abstract public Object get(Object key)
		throws NullPointerException;
	abstract public Object put(Object key, Object element)
		throws NullPointerException;
	abstract public Object remove(Object key)
		throws NullPointerException;
	abstract public Enumeration keys();
	abstract public Enumeration elements();
}
As a rule, the equals method (§20.1.3) should be used by implementations of the class Dictionary to decide whether two keys are the same.

21.4.1 abstract public int size()

The general contract for the size method is that it returns the number of entries (distinct keys) in this dictionary.

21.4.2 abstract public boolean isEmpty()

The general contract for the isEmpty method is that the result is true if and only if this dictionary contains no entries.

21.4.3 abstract public Object get(Object key)
throws NullPointerException

The general contract for the isEmpty method is that if this dictionary contains an entry for the specified key, the associated element is returned; otherwise, null is returned.

If the key is null, a NullPointerException is thrown.

21.4.4 abstract public Object put(Object key, Object element)
throws NullPointerException

The general contract for the put method is that it adds an entry to this dictionary.

If this dictionary already contains an entry for the specified key, the element already in this dictionary for that key is returned, after modifying the entry to contain the new element.

If this dictionary does not already have an entry for the specified key, an entry is created for the specified key and element, and null is returned.

If the key or the element is null, a NullPointerException is thrown.

21.4.5 abstract public Object remove(Object key)
throws NullPointerException

The general contract for the remove method is that it removes an entry from this dictionary.

If this dictionary contains an entry for the specified key, the element in this dictionary for that key is returned, after removing the entry from this dictionary.

If this dictionary does not already have an entry for the specified key, null is returned.

If the key is null, a NullPointerException is thrown.

21.4.6 abstract public Enumeration keys()

The general contract for the keys method is that an Enumeration (§21.1) is returned that will generate all the keys for which this dictionary contains entries.

21.4.7 abstract public Enumeration elements()

The general contract for the elements method is that an Enumeration (§21.1) is returned that will generate all the elements contained in entries in this dictionary.


Contents | Prev | Next | Index

Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to [email protected]