Hashtable toString Example


Hashtable class toString example.public String toString() Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space). Each entry is rendered as the key, an equals sign =, and the associated element, where the toString method is used to convert the key and element to strings.

Here is the code

/**
 * @ # Clear.java
 * A class repersenting use to clear method 
 * of HashMap class in java.util package
 * version 19 May 2008
 * author Rose India 
 */
import java.util.*;

public class ToString {

    public static void main(String args[]) {
        Hashtable table = new Hashtable();

        //Put value into the table
        table.put(1"A");
        table.put(2"B");
        table.put(3"C");
        table.put(4"D");

        //a string representation of this Hashtable 
        //object in the form of a set of entries
        String str=table.toString();
        System.out.println("table :" + str);
    }
}

Output
 table :{4=D, 3=C, 2=B, 1=A}

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US