While studying Java Collections , i cannot understand the main difference between HashMap and LinkedHashMap ? From what i understand The below given codes, HashMap does not maintain insertion order, but LinkedHashMap does ? Is this the only difference.
Output : a,b,c
Secondly how do you iterate over the values in a HashMap and HashTable ? Are we supposed to reuse the key returned by the keySet to get the value of the key ? Secondly a Set does not allow duplicates, so what about duplicate keys ?
A map doesn't allow duplicate keys.
Yes you need to use the keySet's key to iterate over a map.
You can find the details of both HashMap and LinkedHashMap in the javadocs to find their differences, you already pointed out the main difference between the two...
Sajjad Dar wrote:You said that a MAP does not allow duplicate keys, but i understand a Hashtable does ? Is this correct. Both implement the MAP interface ?
If it is correct, then the documentation would mention it. The documentation would also mention what interfaces it implements. So how about if you have a look there? That's what the docs are for, after all. Let us know what you find out.
subject: Difference between HashMap and LinkedHashMap