aspose file tools
The moose likes Beginning Java and the fly likes Comparison of LinkedHashMap & HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Comparison of LinkedHashMap & HashMap" Watch "Comparison of LinkedHashMap & HashMap" New topic
Author

Comparison of LinkedHashMap & HashMap

Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
Hi there.Just looking on page 544 of the (Highly revered )
K&B SCJP book and in relation to LinkedHashMap, I see that
the text states that LinkedHashMap is quicker than HashMap
for adding and removing elements. Im just wondering, how so?
Many thanks & best regards.
K
[ June 19, 2008: Message edited by: Keith Nagle ]

SCJP 5.0
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Hmmm... According to Eckel's Thinking in Java, Choosing between Maps...
LinkedHashMap is slightly slower than HashMap because it maintains the linked list in addition to the hashed data structure.

Of course, the comparisons Eckel provides come with a disclaimer: "...this will be different according to the computer and JVM you are using..." And if you study the table of test results he provides, you will also see that the size of the Map makes a difference.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
Great stuff marc.
Thank you very much.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Comparison of LinkedHashMap & HashMap
 
Similar Threads
Map Question
displaying key of a hashmap,wrong order
Doubt Figure 7-2 K&B
LinkedHasMap Question
Objects and Collections