Java Hashtable(int initialCapacity, float loadFactor) Constructor

Syntax

Hashtable(int initialCapacity, float loadFactor) constructor from Hashtable has the following syntax.

public Hashtable(int initialCapacity,   float loadFactor)

Example

In the following code shows how to use Hashtable.Hashtable(int initialCapacity, float loadFactor) constructor.


import java.util.Hashtable;
/*from   w  w w  .  j  av a  2  s.  com*/
public class Main {
   public static void main(String args[]) {

      Hashtable<Integer, String> htable = new Hashtable<Integer, String>(10,0.75F);

      // put values into the table
      htable.put(1, "A");
      htable.put(2, "B");
      htable.put(3, "C");
      htable.put(4, "from java2s.com");
      
      // check table content
      System.out.println("Hash table content: "+htable);
      
      // clear the table
      htable.clear();
      
      // check content after clear
      System.out.println("Hash table content after clear: "+htable);      
   }    
}

The code above generates the following result.