This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList and LinkedList  RSS feed

 
harsha balluru
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that ArrayList is mainly for faster iteration and fast random access while LinkedList for faster insertion and deletion. Both are ordered but not sorted. My question is that "does anyone disagree if I say LinkedList is ordered by 'insertion order'(or last accessed order)?"
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is that "does anyone disagree if I say LinkedList is ordered by 'insertion order'(or last accessed order)?"


I would tend to disagree. Yes, if you only use the add(Element) method, then the list would be in "insertion order", the order which the elements were inserted. However, the List also have the ability to add() at a particular index, so the order may not be the order the elements were added.

Henry
 
harsha balluru
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!