In this example we will show how to get the size of Hashtable with size method in Java.
Source Code
package com.beginner.examples;
import java.util.Hashtable;
public class GetSizeOfHashtable {
public static void main(String[] args) {
//create Hashtable.
Hashtable hashtable = new Hashtable();
hashtable.put("1","Alice");
hashtable.put("2","Bob");
hashtable.put("3","Jack");
/*
* To get the size of Hashtable use size() method of Hashtable.
*/
System.out.println("The size of Hashtable is " + hashtable.size());
}
}
Output:
The size of Hashtable is 3
References
Imported packages in Java documentation: