java.util.Hashtable.toString() Method
Advertisements
Description
The toString() method is used to get a string representation of this Hashtable object in the form of a set of entries.
Declaration
Following is the declaration for java.util.Hashtable.toString() method.
public String toString()
Parameters
NA
Return Value
The method call returns a string representation of this hashtable.
Exception
NA
Example
The following example shows the usage of 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());
}
}
Let us compile and run the above program, this will produce the following result.
String form of hash table is: {5=TUTORIAL, 4=BEST, 3=THE, 2=IS, 1=TP}