CHAPTER 21: The Package java.util Previous
Previous
Java Language
Java Language
Index
Index
Next
Next

21.4 The Class java.util.Dictionary

21.4.1 size , 21.4.2 isEmpty , 21.4.3 get , 21.4.4 put , 21.4.5 remove , 21.4.6 keys , 21.4.7 elements

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 (S20.1.3) should be used by implementations of the class Dictionary to decide whether two keys are the same.


21.4.1 size

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 isEmpty

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 get

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 put

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 remove

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 keys

abstract public Enumeration keys()

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


21.4.7 elements

abstract public Enumeration elements()

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

Top© 1996 Sun Microsystems, Inc. All rights reserved.