java - ArrayList, LinkedList and Vector which one is the best for adding or removing the element from the list -


i appeared interview interviewer asked me arraylist, linked list , vector. question was
arraylist, linkedlist, , vector implementations of list interface. of them efficient adding , removing elements list ? , supposed answer including other alternatives may aware of.
answered him seems little not impressed answer.
can tell me more ?
thank you

  • linkedlist implemented double linked list. it's performance on add , remove better arraylist, worse on , set methods.you have traverse list point in cases. so, not linkedlist.

  • arraylist implemented resizable array. more elements added arraylist, size increased dynamically. it's elements can accessed directly using , set methods, since arraylist array.

  • vector similar arraylist, synchronised.

arraylist better choice if program thread-safe. vector , arraylist require more space more elements added. vector each time doubles array size, while arraylist grow 50% of size each time.

linkedlist, however, implements queue interface adds more methods arraylist , vector, such offer(), peek(), poll(), etc.

a lot dependent on kind of requirement working on. decision can taken depending upon needs.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -