Abstract Class Dictionary in Java

digitization, transformation, binary

Abstract Class Dictionary in Java

The Dictionary class is the abstract parent of any class which maps keys to values like Hashtable. Any key needs to be a non-null object and corresponding value also needs to be non-null. Key/value pairs can be stored in a Dictionary, and values can be retrieved or removed using their associated keys.

A subclass of Dictionary should use the equals() method to decide if two keys are equivalent. So this abstract class is the superclass of Hashtable. Other hashtable-like data structures might also extend this class.

Ads code goes here

The class Dictionary is described as below:

public abstract class java.util.Dictionary extends java.lang.Object{
//constructor
public Dictionary();//Creates a new Dictionary object.
//Methods:
public abstract Enumeration elements();
public abstract Enumeration keys();
public abstract Object get(Object key);
public abstract boolean isEmpty();
public abstract Object put(Object key,Object value);
public abstract Object remove(Object key);
public abstract int size();
}
 

The details of the class structure are given as follows:

public Dictionary();

public Dictionary() constructor creates an empty Dictionary.

public abstract Enumeration elements();

public abstract Enumeration elements() method returns an Enumeration that iterates through the values in this Dictionary.

This method returns the values in the dictionary as an Enumeration.

public abstract Enumeration keys();

public abstract Enumeration keys() method returns an Enumeration that iterates through the keys in this Dictionary.

This method returns the keys in the dictionary as an Enumeration.

public abstract Object get(Object key);

public abstract Object get(Object key) method returns the value that is associated with the given key.

READ  Class InstantiationError in Java

This method returns the value that corresponds to this key.

Parameter
key – The key of the value to retrieve.

public abstract boolean isEmpty();

public abstract boolean isEmpty() method returns a boolean value that indicates whether or not the Dictionary is empty.

This method returns true if there are no values in the Dictionary; false otherwise.

public abstract Object put(Object key,Object value);

public abstract Object put(Object key, Object value) method associates the given key with the given value in this Dictionary.

This method returns the previous value associated with the given key or null if the key has not previously been
associated with a value.

Parameter
key – A key object.
value – A value object.

public abstract Object remove(Object key);

public abstract Object remove(Object key) method removes a key/value pair from this Dictionary. If the given key is not in the Dictionary, the method does nothing.

This method returns the value associated with the given key or null if the key is not associated with a value.

Parameter
key – The key to the value to remove.

public abstract int size();

public abstract int size() method returns the number of key/value pairs in this Dictionary.

This method returns the number of keys in the Dictionary.

Apart from these MNO class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)

Share and Enjoy !

Leave a Comment

Your email address will not be published. Required fields are marked *