• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Difference between HashMap and LinkedHashMap

 
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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 b,a,c


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 ?
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi .. Thanks for the reply. You said that a MAP does not allow duplicate keys, but i understand a Hashtable does ? Is this correct. Both implement the MAP interface ?
 
Sheriff
Posts: 28385
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic