Bootstrap FreeKB - Java - Define an empty hash table
Java - Define an empty hash table

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 559f46 in the box below so that we can be sure you are a human.