ArrayList and LinkedList in Java

shivambhateleshivambhatele Posts: 2

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

  • rohanjoshi0894rohanjoshi0894 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.

  • satineerajsatineeraj 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

Sign In or Register to comment.