Important Java Interview Questions - Part 5

I'm sharing my experience with you as these are the questions which have been asked to me while interviewing on java profile.

What is difference between Linkedlist & Arraylist?

LinkedList is an implementation of List interface in java. The LinkedList Java class is a concrete implementation of this abstract concept. LinkedList is based on double linked List data structure. LinkedList<E> allows for constant-time insertions or removals using iterators, but only sequential access of elements and maintains insertion order. LinkedList is non synchronized.

ArrayList is an implementation of List interface in java. ArrayList is based on an Array data structure. ArrayList implements it with a dynamically re-sizing array and maintains insertion order. It is non synchronized.



ArrayList
LinkedList
1) ArrayList internally uses dynamic array to store the elements.
LinkedList internally uses doubly linked list to store the elements.
2) ArrayList class can act as a list only because it implements List only.
LinkedList class can act as a list and queue both because it implements List and Deque interfaces.
3) Manipulation with ArrayList is slow because it internally uses array. If any element is removed from the array, all the bits are shifted in memory.
Manipulation with LinkedList is faster than ArrayList because it uses doubly linked list so no bit shifting is required in memory.
4) ArrayList is better for storing and accessing data.
LinkedList is better for manipulating data.
5) ArrayList being faster than LinkedList is that ArrayList uses index based system for its elements as it internally uses array data structure.
LinkedList does not provide index based access for its elements as it iterates either from the beginning or end (whichever is closer) to retrieve the node at the specified element index.
6) LinkedList can be iterated in reverse direction using descendingIterator().
There is no descendingIterator() in ArrayList , so we need to write our own code to iterate over the ArrayList in reverse direction.
7) LinkedList only constructs the empty list without any initial capacity.
If the constructor is not overloaded , then ArrayList creates an empty list of initial capacity 10.


If you still have any question you can reach me any time through email (jigyasu2010@hotmail.com)

Comments

Popular posts from this blog

How Method Overloading Helping in Java - Part 9

Important Java Interview Questions - Part 7

Access Modifiers in java