I wrote a standalone program, trying to put 10k elements in a hasmap and hashtable; here I observed hashtable is faster than hashmap for insertion.
HashMap: (Taken time: 31ms)
public static void main(String[] args) {
long s = System.currentTimeMillis();
Map<String, Integer> map = new HashMap<String, Integer>();
for (int i = 0; i < 10000; i++) {
map.put("i_" + i, i);
}
System.out.println("Taken time: " + (System.currentTimeMillis() - s));
}
HashTable: (Taken time: 15ms)
public static void main(String[] args) {
long s = System.currentTimeMillis();
Map<String, Integer> map = new Hashtable<String, Integer>();
for (int i = 0; i < 10000; i++) {
map.put("i_" + i, i);
}
System.out.println("Taken time: " + (System.currentTimeMillis() - s));
}
Is that understanding correct?