概念题

Screen Shot 2016-11-18 at 5.22.16 PM.png

Explain

  1. Get: ArrayList maintains index based system for its elements as it uses array data structure implicitly which makes it faster for searching. LinkedList implements doubly linked list which requires the traversal through all the elements for searching.
  2. Remove & Add: LinkedList’s each element maintains two pointers which points to the both neighbor elements. Hence removal only requires change in the pointer location in the two neighbor nodes of the node which is going to be removed. While In ArrayList all the elements need to be shifted to fill out the space created by removed element.
  3. Memory Overhead: ArrayList maintains indexes and element data while LinkedList maintains element data and two pointers for neighbor nodes.

When to use LinkedList and ArrayList?

If there is a requirement of frequent addition and deletion in application then LinkedList is a best choice.

If there are less add and remove operations and more search operations requirement, ArrayList would be your best bet.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容