VOOZH about

URL: https://www.geeksforgeeks.org/java/hashtable-size-method-in-java/

⇱ Hashtable size() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Hashtable size() Method in Java

Last Updated : 2 Jun, 2023

The java.util.Hashtable.size() method of Hashtable class is used to get the size of the table which refers to the number of the key-value pair or mappings in the Table. 

Syntax:

Hash_Table.size()

Parameters: The method does not take any parameters. 

Return Value: The method returns the size of the table which also means the number of key-value pairs present in the table. Below programs illustrates the working of java.util.Hashtable.size(): 

Program 1: 

Output:
Initial table is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes}
The size of the table is 5

Program 2: 

Output:
Initial Table is: {You=30, Welcomes=25, 4=15, Geeks=20}
The size of the table is 4

Note: The same operation can be performed with any type of variation and combination of different data types.

Comment
Article Tags: