Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java Dictionary Class

Java Dictionary Class

Java Data StructuresJava Data Structures


The Dictionary class is an abstract class used to store key/value pairs, and its function is similar to the Map class.

Given a key and a value, you can store the value in a Dictionary object. Once stored, it can be retrieved by its key. So, like Map, Dictionary can also serve as a list of key/value pairs.

The abstract methods defined by Dictionary are shown in the table below:

No. Method Description
1 Enumeration elements( )
Returns an enumeration of the values in this dictionary.
2 Object get(Object key)
Returns the value to which this key is mapped in this dictionary.
3 boolean isEmpty( )
Tests whether this dictionary has no mapping from key to value.
4 Enumeration keys( )
Returns an enumeration of the keys in this dictionary.
5 Object put(Object key, Object value)
Maps the specified key to the specified value in this dictionary.
6 Object remove(Object key)
Removes the key (and its corresponding value) from this dictionary.
7 int size( )
Returns the number of entries (distinct keys) in this dictionary.

The Dictionary class is obsolete. In actual development, you canimplement the Map interfaceto obtain key/value storage functionality.


Java Data StructuresJava Data Structures