Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections : Help Needed

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on Page 542 :
ArrayList : Choose this over a LinkedList when you need fast iteration but aren't as likely to be doing a lot of insertion and deletion.

AND

on page 544 : Although itwill be somewhat slower than HashMap for adding and removing elements, you can expect faster iteration with a LinkedHashMap.

This means that one must choose {ArrayList over LinkedList} and {LinkedHashMap over HashMap} for fast iteration. Is this correct or a typo (bug) as these 2 statements are oposite of each other...
 
Bing Qiao
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had doubt about that too.

But then I thought maybe it was due to the difference between Map and List.
 
Matthew Gerald
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found an interesting link here:

http://www.javafaq.nu/java-articles-archive-461.html

It seems as though the book is correct due to LinkedHashMap actually using a LinkedList for iteration purposes. So what I'm assuming is that the LinkedList iteration is faster than HashMap iteration. So, LinkedHashMap is then faster for iteration than HashMap due to using that LinkedList.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic