Important Java Interview Questions - Part 6

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



Why linkedlist is good for insertion in java?

A LinkedList looks like a chain, consisting of people who hold each other's hand. You can insert people or node into that chain or remove. LinkedList is actually very flexible extension of an ArrayList, For example if you need to add new element to the end of an ArrayList you have to look at the size of the collection and then add that new element at n+1 place. In LinkedList you do it directly by addLast(E e) method.


In a LinkedList there are three parts. First part stores the pointer to previous element, second stores the data & third stores pointer to next element. So when insertion & deletion happens in linkedlist these pointers get updated. Thats why linkedlist is fast. Whereas, ArrayList internally uses array & when you run an “add” command a new Array of size more than old array will be created and in deletion that internal array will be modified.

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