1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Java Tutorials

Q.Difference between ArrayList and LinkedList?

ArrayList is good for adding and removing elements from the end of the container. All of these operations can be performed in constant time -- O(1).
adding and removing elements from any other position proves more expensive -- linear to be exact: O(n-i), where n is the number of elements and i is the index of the element added or removed.
For Example : ArrayList Has 5 elements and you want to add an element on 2nd position.
Then arrayList add the element on 2nd position and shifted existing 2nd position element to 3rd , 3rd position element to 4th etc..

LinkedList can add or remove an element at any position in constant time -- O(1). Indexing an element is a bit slower -- O(i) where i is the index of the element in case of LinkedList.

Traversing an ArrayList is also easier since you can simply use an index instead of having to create an iterator.
The LinkedList creates an internal object for each element inserted. So you have to be aware of the extra garbage being created.

An ArrayList is a List implementation backed by a Java array.
With a LinkedList, the List implementation is backed by a doubly linked list data structure

Reviews and Comments

PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016

About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy