util.Dictionary é uma classe abstrata, que representa uma relação de valor-chave e funciona de forma semelhante a um mapa. Dada uma chave, você pode armazenar valores e, quando necessário, recuperar o valor usando sua chave. Portanto, é uma lista de pares de valores-chave.
Declaração

public abstract class Dictionary extends Object

Construtores:
Dicionário() Construtor único.
Métodos da classe util.Dictionary:

  1. put (chave K, valor V): java.util.Dictionary.put (chave K, valor V) adiciona par de valor-chave ao dicionário
    Sintaxe:
    Parâmetros públicos abstratos V put (chave K, valor V)
     :
    -> chave
    -> valor
    Retornar : 
    par de valores-chave mapeado no dicionário
    
  2. elements(): java.util.Dictionary.elements() retorna a representação do valor no dicionário
    Sintaxe:
    Elementos de enumeração abstratos públicos()
     Parâmetros:
    --------
    Retornar : 
    enumeração de valor no dicionário
    
  3. get (Object key): java.util.Dictionary.get (Object key) retorna o valor que é mapeado com a chave argumentada no dicionário
    Sintaxe:

    Parâmetros public abstract V get (Object key)
     :
    key - chave cujo valor mapeado desejamos
    Retornar : 
    valor mapeado com a chave argumentada
    
  4. isEmpty(): java.util.Dictionary.isEmpty() verifica se o dicionário está vazio ou não.
    Sintaxe:
    Parâmetros public abstract boolean isEmpty()
     :
    ------
    Retornar : 
    verdadeiro, se não houver relação de valor-chave no dicionário; mais falso
    
  5. keys(): java.util.Dictionary.keys() retorna a representação da chave no dicionário
    Sintaxe:
    Chaves de enumeração abstratas públicas()
     Parâmetros:
    --------
    Retornar : 
    enumeração chave no dicionário
    
  6. remove (Object key): java.util.Dictionary.remove (Object key) remove o par chave-valor mapeado com a chave argumentada.
    Sintaxe:
    Parâmetros public abstract V remove (Object key)
     :
    chave: chave a ser removida
    Retornar : 
    valor mapeado com a chave
    
  7. size(): java.util.Dictionary.size() retorna o não. de pares de valores-chave na sintaxe do dicionário
    :
    public abstract int size()
     Parâmetros:
    -------
    Retornar : 
    retorna o não. de pares de valores-chave no Dicionário
    
// Java Program explaining util.Dictionary class Methods
// put(), elements(), get(), isEmpty(), keys()
// remove(), size()
  
import java.util.*;
public class New_Class
{
    public static void main(String[] args)
    {
  
        // Initializing a Dictionary
        Dictionary geek = new Hashtable();
  
        // put() method
        geek.put("123", "Code");
        geek.put("456", "Program");
  
        // elements() method :
        for (Enumeration i = geek.elements(); i.hasMoreElements();)
        {
            System.out.println("Value in Dictionary : " + i.nextElement());
        }
  
        // get() method :
        System.out.println("\nValue at key = 6 : " + geek.get("6"));
        System.out.println("Value at key = 456 : " + geek.get("123"));
  
        // isEmpty() method :
        System.out.println("\nThere is no key-value pair : " + geek.isEmpty() + "\n");
  
        // keys() method :
        for (Enumeration k = geek.keys(); k.hasMoreElements();)
        {
            System.out.println("Keys in Dictionary : " + k.nextElement());
        }
  
        // remove() method :
        System.out.println("\nRemove : " + geek.remove("123"));
        System.out.println("Check the value of removed key : " + geek.get("123"));
  
        System.out.println("\nSize of Dictionary : " + geek.size());
  
    }
}

Saída:

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

Este artigo é uma contribuição de Mohit Gupta_OMG ? . Se você gosta de GeeksforGeeks e gostaria de contribuir, você também pode escrever um artigo usando contribute.geeksforgeeks.org ou enviar o seu artigo para contribute@geeksforgeeks.org. Veja o seu artigo na página principal do GeeksforGeeks e ajude outros Geeks.

Escreva comentários se encontrar algo incorreto ou se quiser compartilhar mais informações sobre o tópico discutido acima.