Dictionary in java

Dictionary is an abstract class that represents a key/value storage repository and operates much like Map. Given a key and value, you can store the value in a Dictionary object. Once the value is stored, you can retrieve it by using its key. Thus, like a map, a dictionary can be thought of as a list of key/value pairs. Although not currently deprecated, Dictionary is classified as obsolete, because it is fully superseded by Map

class Dictionary<K, V>

Here, specifies the type of keys, and specifies the type of values

The Abstract Methods Defined by Dictionary

Enumeration<V> elements( )Returns an enumeration of the values contained in the dictionary.
V get(Object key)Returns the object that contains the value associated with key. If
 key is not in the dictionary, a null object is returned.
boolean isEmpty( )Returns true if the dictionary is empty, and returns false if it
 contains at least one key.
Enumeration<K> keys( )Returns an enumeration of the keys contained in the dictionary.
V put(K key, V value)Inserts a key and its value into the dictionary. Returns null if key
 is not already in the dictionary; returns the previous value
 associated with key if key is already in the dictionary.
V remove(Object key)Removes key and its value. Returns the value associated with
 key. If key is not in the dictionary, a null is returned.
int size( )Returns the number of entries in the dictionary.
The Abstract Methods Defined by Dictionary

To add a key and a value, use the put( ) method. Use get( ) to retrieve the value of a given key. The keys and values can each be returned as an Enumeration by the keys( ) and elements( ) methods, respectively. The size( ) method returns the number of key/value pairs stored in a dictionary, and isEmpty( ) returns true when the dictionary is empty. You can use the remove( ) method to delete a key/value pair.

Leave a Comment