Método Hashtable isEmpty() em Java
O método java.util.Hashtable.isEmpty() da classe Hashtable é usado para verificar o vazio da tabela. O método retorna True se nenhum par de valores-chave ou mapeamento estiver presente na tabela, caso contrário, False.
Sintaxe:
Hash_Table.isEmpty()
Parâmetros: o método não aceita nenhum parâmetro.
Valor de retorno: O método retorna verdadeiro booleano se a tabela estiver vazia ou não contiver nenhum par de mapeamento, senão falso booleano.
Os programas abaixo ilustram o funcionamento do método java.util.Hashtable.isEmpty():
Programa 1:
// Java code to illustrate the isEmpty() method
import java.util.*;
public class Hash_Table_Demo {
public static void main(String[] args)
{
// Creating an empty Hashtable
Hashtable<String, Integer> hash_table =
new Hashtable<String, Integer>();
// Inserting elements into the table
hash_table.put("Geeks", 10);
hash_table.put("4", 15);
hash_table.put("Geeks", 20);
hash_table.put("Welcomes", 25);
hash_table.put("You", 30);
// Displaying the Hashtable
System.out.println("The table is: " + hash_table);
// Checking for the emptiness of Table
System.out.println("Is the table empty? " +
hash_table.isEmpty());
}
}
A tabela é: {You = 30, Welcome = 25, 4 = 15, Geeks = 20} A mesa está vazia? falso
Programa 2:
// Java code to illustrate the isEmpty() method
import java.util.*;
public class Hash_Table_Demo {
public static void main(String[] args)
{
// Creating an empty Hashtable
Hashtable<String, Integer> hash_table = new Hashtable<String, Integer>();
// Displaying the Hashtable
System.out.println("The table is: " + hash_table);
// Checking for the emptiness of Table
System.out.println("Is the table empty? " + hash_table.isEmpty());
}
}
A mesa é: {} A mesa está vazia? verdade
Nota: A mesma operação pode ser realizada com qualquer tipo de variação e combinação de diferentes tipos de dados.
As postagens do blog Acervo Lima te ajudaram? Nos ajude a manter o blog no ar!
Faça uma doação para manter o blog funcionando.
70% das doações são no valor de R$ 5,00...
Diógenes Lima da Silva