int size()
描述 (Description)
size()方法用于获取此哈希表中的键数。
声明 (Declaration)
以下是java.util.Hashtable.size()方法的声明。public int size()
参数 (Parameters)
NA
返回值 (Return Value)
方法调用返回此哈希表中的键数。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.Hashtable.size()的用法package com.iowiki;
import java.util.*;
public class HashTableDemo {
public static void main(String args[]) {
// create hash table
Hashtable htable = new Hashtable(3);
// populate the table
htable.put(1, "TP");
htable.put(2, "IS");
htable.put(3, "THE");
htable.put(4, "BEST");
htable.put(5, "TUTORIAL");
System.out.println("Size of the hash table is: "+htable.size());
}
}
让我们编译并运行上面的程序,这将产生以下结果。Size of the hash table is: 5