vector vs Linked list


Performance and scalability: vector vs Linked list

  1. vector vs Linked list (7 messages)


    Somebody please tell me diff between vector and linked list ? When to use which ? URGENT.


    Threaded Messages (7)

  2. vector vs Linked list[ Go to top ]

    A vector is a growable array. u can store any object derived from the object class) to it.

    A linked list is a list where each item in the list have a link to the next item. u can use linked-list to implement queue or stack.

    BTW, such answer can be easily found from any comp science text book or from the internet itself. i strongly believe that u should not post such question in this column.


  3. vector vs Linked list[ Go to top ]

    Actually, a question _like_ this may be very valid for this forum if the reason it's being asked has to do with performance. I do not believe the original question is being asked for this reason, and as such I agree with you.

    I would like to point out that with respect to performance, the decision on which to use may be very relevant.

    As per the javadoc, which you should look at before posting your question, the LinkedList is not sychronized, but Vector is. This has performance and behaviour implications.

    I advise the poster to check the docs, and refer to the source code if necessary.

    My 2 cents...
  4. vector vs Linked list[ Go to top ]

    Its an even bigger issue when you look at the cost of marshalling that Vector. Vector can be an incredibly expensive object to serialize.

    Dave Wolf
    Internet Applications Division
  5. vector vs Linked list[ Go to top ]

    If you don't want the synchronization overhead of a Vector use and ArrayList, they pretty much have the exact same function just ArrayList isn't synchronized.
  6. vector vs Linked list[ Go to top ]

    First, I would recommend picking up the book Practical Java. It has excellent tips that cover this area, and my subsequent comments come from tips I gleaned from that book.

    Anyway, as a general rule, prefer an ArrayList to a Vector or LinkedList. The ArrayList is essentially a unsynchronized Vector, making it faster. If you need synchronization, obviously, it is not such an obvious choice. As compared to the Linked List, I quote here from the Java API documentation:
    "The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation."

    Faster than any of these options, and perhaps therefore preferrable, is simple using an array. ArrayLists and Vector essentially amount to this, with some nice convenient add and remove features, among others. Nothing, though, really that can't be implemented easily with an array. The performance boon, supposedly, is something on the level of 17x. Not bad.
  7. vector vs Linked list[ Go to top ]

    hi John Kelvie,

    Thanks for helping me in taking decision which is to be used. Actually i was in the middle of once performance tuning operation so just looking for the options.

    What ever may be the aim of the initiator of this thread, vijji v, it helped me a lot.

    Also thanks for suggeting a good book, i'll look for it if at all i can get it some where.
  8. Re: vector vs Linked list[ Go to top ]

    BTW, such answer can be easily found from any comp science text book or from the internet itself.
    This is the Internet! This page is one of the first results for "java vector versus list" on Google... And your response is not particularly helpful. Continuing on to other results...