Java.util.Dictionary Class in Java
util. Dictionary is an abstract class, representing a key-value relation and works similar to a map. Given a key, you can store values and when needed can retrieve the value back using its key. Thus, it is a list of key-value pairs.
Declaration
public abstract class Dictionary extends Object
Constructors:
Dictionary() Sole constructor.
Methods of util.Dictionary Class :
- put(K key, V value) : java.util.Dictionary.put(K key, V value) adds key-value pair to the dictionary
Syntax : -
public abstract V put(K key, V value) Parameters : -> key -> value Return : key-value pair mapped in the dictionary
- elements() : java.util.Dictionary.elements() returns value representation in dictionary
Syntax :public abstract Enumeration elements() Parameters : -------- Return : value enumeration in dictionary
- get(Object key) : java.util.Dictionary.get(Object key) returns the value that is mapped with the argumented key in the dictionary
Syntax :public abstract V get(Object key) Parameters : key - key whose mapped value we want Return : value mapped with the argumented key
- isEmpty() : java.util.Dictionary.isEmpty() checks whether the dictionary is empty or not.
Syntax :public abstract boolean isEmpty() Parameters : ------ Return : true, if there is no key-value relation in the dictionary; else false
- keys() : java.util.Dictionary.keys() returns key representation in dictionary
Syntax :public abstract Enumeration keys() Parameters : -------- Return : key enumeration in dictionary
- remove(Object key) : java.util.Dictionary.remove(Object key) removes the key-value pair mapped with the argumented key.
Syntax :public abstract V remove(Object key) Parameters : key : key to be removed Return : value mapped with the key
- size() : java.util.Dictionary.size() returns the no. of key-value pairs in the Dictionary
Syntax :public abstract int size() Parameters : ------- Return : returns the no. of key-value pairs in the Dictionary
-
Output:
Value in Dictionary : Code Value in Dictionary : Program Value at key = 6 : null Value at key = 456 : Code There is no key-value pair : false Keys in Dictionary : 123 Keys in Dictionary : 456 Remove : Code Check the value of removed key : null Size of Dictionary : 1
post a comment