Win a copy of Head First Android this week in the Android forum!
  • 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 Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Why iteration in LinkedList is slow while insertion and deletion is faster that ArrayList and Vector

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why iteration in LinkedList is slow while insertion and deletion is faster that ArrayList and Vector,
while LinkedHashSet is faster for iteration while but slower for insertion/deletion that HashSet Please Explain....
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aman,

Looking at LinkedList vs. ArrayList and it says -


ArrayList - The ArrayList is actually encapsulating an actualy Array, an Object[].

LinkedList - The LinkedList is implemented using nodes linked to each other. Each node contains a previous node link, next node link, and value, which contains the actual data.



The definitions explain why iteration in LinkedList is slow while insertion and deletion is faster than ArrayList and Vector.

In a LinkedList one has to traverse the list via links from one node to another, versus the simpler array.

For insertions and deletions, in a LinkedList, only a couple of references need to change while in an ArrayList an entire section of the array need to shift.

Regards,
Dan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic