java.util.Hashtable.toString() 方法
描述
toString() 方法用于以一组条目的形式获取此 Hashtable 对象的字符串表示形式。
声明
以下是 java.util.Hashtable.toString() 方法的声明。
public String toString()
参数
NA
返回值
方法调用返回此哈希表的字符串表示形式。
异常
NA
示例
下面的例子展示了 java.util.Hashtable.toString() 的用法。
package com.tutorialspoint;
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("String form of hash table is: "+htable.toString());
}
}
让我们编译并运行上面的程序,这将产生以下结果.
String form of hash table is: {5=TUTORIAL, 4=BEST, 3=THE, 2=IS, 1=TP}

