| |
Hashtable implements java.util.Map Interface ---Java Collections -Hashtable
// Java Example Of Hashtable
import java.util.Enumeration;
import java.util.Hashtable;
public class HashTableDemoExample {
public Hashtable buildHashTable(){
Hashtable hashTable = new Hashtable();
hashTable.put( "Name" , "Venugopal Darur" );
hashTable.put( "RollNo" , "639" );
hashTable.put( "College" , "Vasavi College Of Engineering" );
hashTable.put( "City" , "Hyderabad" );
hashTable.put( "State" , "Andhra Pradesh" );
hashTable.put( "Country" , "India" );
return hashTable;
}
public void prinHashTable( Hashtable hashTable ){
Enumeration enumerator = hashTable.keys();
while ( enumerator.hasMoreElements() ){
String key = ( String ) enumerator.nextElement();
String value = ( String ) hashTable.get( key );
System.out.println( key + "\t\t: \t" + value );
}
}
public static void main( String [] args ){
HashTableDemo hashtableDemo = new HashTableDemo( );
Hashtable hashtable =hashtableDemo.buildHashTable();
hashtableDemo.prinHashTable( hashtable );
}
}
Output :
Name : Venugopal Darur
State : Andhra Pradesh
City : Hyderabad
College : Vasavi College Of Engineering
RollNo : 639
Country : India
// Hashtable cannot store even one Null Value
Please send comments to vgdarur.javafive@blogger.com
|