import java.util.*;
class Hashtable1{
public static void main(String args[]){
Hashtable<Integer,String> hm=new Hashtable<Integer,String>();
hm.put(100,"Amit");
hm.put(102,"Ravi");
hm.put(101,"Vijay");
hm.put(103,"Rahul");
for(Map.Entry m:hm.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
}
}
- HashTable don't have null key, sychronized(thread-safe)
Good for parallel testing
- HashTable don't have null key, sychronized(thread-safe)
good for parallel testing
//Java Hashtable
//--------------
import java.io.*;
import java.util.*;
class AddElementsToHashtable {
public static void main(String args[])
{
Hashtable<Integer, String> h1 = new Hashtable<>();
// Initialization of a Hashtable using Generics
Hashtable<Integer, String> h2 = new Hashtable<Integer, String>();
// Inserting the Elements using put() method
// ------------
ht1.put(1, "Chris");
ht1.put(2, "Tony");
ht1.put(3, "Peter");
ht2.put(4, "Steven");
// Print mappings to the console (Output)
System.out.println("Mappings of Hash Table 1 : " + h1);
System.out.println("Mappings of Hash Table 2 : " + h2);
}
}