Dictionary in Java

The Dictionary class represents a key-value relation which maps keys to values. In Dictionary class, every key and every value is an object.

It is an abstract class associated with Java since JDK 1.0. In Dictionary, every key is associated with at most one value and any object that contains some value can be used as a key and as a value.

Dictionary in Java

The Dictionary class is deprecated, so new implementation should implement the Map interface, rather than extending this class.

Constructor for Dictionary class:

Methods of Dictionary Class

Modifiers Methods Description
      abstract v get(Object key) This method returns the associated value for the specified key in the argument. Otherwise, returns null.
put(K key, V value) It maps the specified key to the specified value in the argument.
remove(Object key) This removes the specified key and its corresponding value from the dictionary. It will do nothing if the specified key is not available in the dictionary.
abstract boolean isEmpty() It tests whether the dictionary maps keys to the value or not. The result will be true if and only if the dictionary is blank.
abstract Emumeration<V> elements() This method returns an enumeration that will generate all the values contained in the entries of the Dictionary.
keys() This method returns a list of the keys present in the dictionary.
abstract int size() It returns the number of entries (key-value) in the Dictionary.

Example to illustrate all the above methods:


Pin It on Pinterest

Share This