Hash Table:
- Like the vector key, methods of the class are synchronized.
- Thread safety and therefore slows the performance.
- It doesn’t allow anything that is null.
Example:
public class Fruit{
public static void main(String[ ]args){
Hashtable<Sting,String> names =new Hashtable<String,String>( );
names.put(“key1”,“cherry”);
names.put(“key2”,“apple”);
names.put(“key3”,“banana”);
names.put(“key4”,“kiwi”);
names.put(“key2”,“orange”);
System.out.println(names);
}
}
Output:
{key2=apple, key1=cherry,key4=kiwi, key3=banana}
Duplicate keys are not allowed.