Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

ArrayList and LinkedList in Java

shivambhatele
shivambhatele Posts: 4

Hello Everyone, I am confused to understand why does ArrayList takes more time to insert elements at the beginning than LinkedList in Java? Can anyone know the exact comparison between ArrayList and LinkedList?

Tagged:

Comments

  • rohanjoshi0894
    rohanjoshi0894 Posts: 1

    It's O(1). As its name (and the Javadoc) shows, ArrayList is internally implemented by arrays. So, inserting an item involves moving all the items behind it one position forward. In the other hand, a LinkedList only has to redirect the references of the items to insert the new node, so its time is more constant.'

    Checkout this post which will help you to get deeper insights between ArrayList and Linkedlist.

  • satineeraj
    satineeraj Posts: 1

    Array always used the homogeneous data element. and these element are stores in the consecutive order. while List are most similar then the Array, it also be used to store the elements. the element in the list will be stored in the heterogeneous order.
    Check the post to check the more about the Array and List

Tagged