This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkList Vs. Vector

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is LinkList?
what is difference between LinkList and Vector?
Thanks,
Angela
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the API for both these classes you will notice that LinkedList extends the
java.util.AbstractSequentialList
while the Vector class extends java.util.AbstractList
The most significant difference in terms of use is that the Vector is an array. You can add elements only at the end.
To the LinkedList you can add elements in the end, in the beginning or anywhere in the middle. That is how you keep the list in a sorted order.
Hope this helps
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Shivaji,
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm... you can add elements at the beginning, middle, or end of either structure. But in some cases, the performace is good - in others, it's really bad. Vectors are good for adding or removing elements near the end - the further you are from the end, the slower it is. LinkedLists are not quite as fast as Vectors at the end of the list, but they're no slower at the beginning or middle, which makes them much better than Vectors for that type of work.
Angela, most of the detailed differences are discussed at length in other forums here - specifically, "Java in General (intermediate)" and "Performance". Try using "search" (in the upper right corner of your screen) to find past discussions in those forums. At the beginner level, all Lists (Vector, ArrayList, LinkedList) are pretty much interchangeable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic