Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query on Collections

 
Ritu Kapoor
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone please let me know that is iteration over linkedlist is faster than an ArrayList.

Regds,
Ritu
 
Manju Devarla
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iteration of LinkedList is not faster than ArryList because elements are doubly linked to one another..
But its a good choice for faster insertion and deletions
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what it's worth, Bruce Eckel's Thinking in Java includes some performance comparisons under the Choosing an implementation section of the Collections chapter...
Oddly, iteration is faster for a LinkedList than an ArrayList, which is a bit counterintuitive.

[ January 25, 2007: Message edited by: marc weber ]
 
Ritu Kapoor
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read a following question from a website.


It says the correct answers are: 1,2
I feel its only 1.

Please help.
Rgds,
Ritu
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manju Devarla:
Iteration of LinkedList is not faster than ArryList because elements are doubly linked to one another...

What does being doubly linked have to to with iteration performance?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following question from a website
. Please tell us which website. If you quote a mock exam question always provide the reference. We will close topics if the source is not quoted. Thanks.
 
Ritu Kapoor
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The source of mock exam is http://www.akgupta.com/Java/mock_exam.htm
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ritu Kapoor:
The source of mock exam is http://www.akgupta.com/Java/mock_exam.htm


Great. Thanks
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic