Thursday, September 1, 2011

HashTable Example


//HashTableExample.java
import java.util.Enumeration;

import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;

public class HashTableExample
{
public static void main(String a[])
{
Hashtable ht = new Hashtable();
for (int i = 0; i < 8; i++)
{
ht.put(i, new Integer(i*10));
}
ht.put(8, 500);
Enumeration it = ht.keys();

System.out.println("Get the key ");
while (it.hasMoreElements())
{
Object object = (Object) it.nextElement();
System.out.println(object);
}

it = ht.elements();
System.out.println("Get the key's value");
while (it.hasMoreElements())
{
Object object = (Object) it.nextElement();
System.out.println(object);
}
}
}

Output =>
Get the key
8
7
6
5
4
3
2
1
0
Get the key's value
500
70
60
50
40
30
20
10
0

No comments:

Post a Comment