Why do I get different results when I run equivalent code for hashtable and hashmaps?
Iterator<Integer> it = ht.keySet().iterator();
while(it.hasNext()) {
i = it.next();
System.out.println(i + " : " + ht.get(i));
}
ht is a hashtable object. If i replace with hm, a hashmap object, it doesn’t print the values from get() method instead prints null. Why is that?
While not technically an “answer” to your question (which is not possible due to insufficient code provided in the question), I do have this suggestion regarding code style.
This would have helped you avoid the bug you found in your code (according to your later comment).
The code you provided:
is equivalent to this more elegant foreach loop over the entry set:
Use this form in preference to using the iterator directly if you can.
It’s neater, and
less code == good