Java - Define an empty hash table
                
            
            
            
             
            
            
                           
                
            
            
            
                
    
    
     
            
                
                    by
                    Jeremy Canfield  |  
                    Updated: August 25 2022
                    
                          |  Java articles
                    
                    
                    
                
            
            Here is an example of how to create three different empty hash tables, one that will contain objects, another for integers, and another for booleans.
public class Main {
  public static void main(String[] args){ 
    Hashtable<String, Object> objecthashtable   = new Hashtable<String, Object>();
    Hashtable<String, Integer> integerhashtable = new Hashtable<String, Integer>();
    Hashtable<String, Boolean> booleanhashtable = new Hashtable<String, Boolean>();
    System.out.println("object hash table  = " + objecthashtable);
    System.out.println("integer hash table = " + integerhashtable);
    System.out.println("boolean hash table = " + booleanhashtable);
  }
}
In this example, System.out.println will just return { }, since each hash table is empty (contains no key value pairs).
object hash table  = {}
integer hash table = {}
boolean hash table = {}
            
            Did you find this article helpful?
If so, consider buying me a coffee over at 