关键区别 - arraylist vsLinkedList
Collections are useful for storing data. In a normalarray,数组大小是固定的。有时是需要d to create arrays that can grow as needed. Programming languages such as爪哇has collections. It is a framework with a set ofclasses and interfaces。It serves as a container for a group of elements. Collections allow to store, update , retrieve set of elements. It helps to work with data structures such aslists,,,,sets,树和地图。该列表是集合框架的接口。ArrayList和LinkedList是集合框架中的两个类。他们实现了集合接口并列表接口。本文讨论了ArrayList和LinkedList之间的区别。ArrayList is a class that extends the AbstractList and implements the List interface, which internally uses a dynamic array to store data elements. LinkedList is a class that extends the AbstractSequentialList and implements List, Deque, and Queue interfaces, which internally use a doubly linked list to store data elements.That is the关键区别在ArrayList和LinkedList之间。
CONTENTS
1。概述和关键差异
2。What is ArrayList
3。LinkedList是什么
4。ArrayList和LinkedList之间的相似之处
5。并排比较 - 表格中的arraylist vs linkedlist
6.Summary
What is ArrayList?
ArrayList类用于创建动态数组。与普通数组不同,动态阵列的大小未固定。使用ArrayList类创建的对象可以在列表中存储一组元素。容量会自动增加,因此程序员可以将元素添加到列表中。ArrayList类扩展了实现列表接口的抽象清单类。因此,列表接口的方法可以由ArrayList使用。要访问元素,使用get()方法。add()方法可用于将元素添加到列表中。remove()方法用于将元素从列表中删除。请参阅以下程序。
根据上面的程序,创建了一个ArrayList的对象。使用添加方法,可以动态添加元素。使用添加方法添加了元素“ A”,“ B”,“ C”,“ D”和“ E”。删除方法用于从列表中删除元素。将4传递到删除方法时,从列表中删除了第四个索引中的字母。当使用for循环遍历列表时,字母A,B,C和D将打印。
什么是LinkedList?
与ArrayList类似,LinkedList用于动态存储数据元素。使用LinkedList类创建的对象可以在列表中存储一组元素。容量会自动增加,因此程序员可以将元素添加到列表中。它在内部使用双重链接列表来存储数据。在双重链接列表中,数据存储为节点。每个节点包含两个链接。第一个链接指向上一个节点。下一个链接指向序列中的下一个节点。
The LinkedList class extends the AbstractSequentialList class and implements the List interface. Therefore, the methods of List interface can be used by the LinkedList. The get() method can be used to access elements of the list. The add() method can be used to add elements to the list. The remove() method is used to remove an element out of the list. Refer the below program.
根据上述程序,创建了linkedlist的对象。使用添加方法,可以动态添加元素。使用添加方法添加了元素“ A”,“ B”,“ C”,“ D”和“ E”。删除方法用于从列表中删除元素。将4传递到删除方法时,第四索引中的字母从列表中删除。使用FO循环迭代时,字母A,B,C和D将打印。
What are the Similarities Between ArrayList and LinkedList?
- Both ArrayList and LinkedList implement List interface.
- ArrayList和LinkedList都可以包含重复的元素。
- ArrayList和LinkedList都保持插入顺序。
What is the Difference Between ArrayList and LinkedList?
ArrayList vsLinkedList |
|
ArrayList is a class that extends the AbstractList and implements the List interface which internally uses a dynamic array to store data elements. | linkedlist是一个扩展AbstractSequentionList的类,并在内部使用双重链接列表来存储数据元素。 |
Accessing Elements | |
Accessing elements of ArrayList is faster than of a LinkedList. | Accessing elements of LinkedList is slower than of an ArrayList. |
操纵元素 | |
Manipulating elements of ArrayList is slower than of a LinkedList. | LinkedList的操纵元素比阵列列表更快。 |
Behavior | |
ArrayList performs as a List. | LinkedList performs as a List and a Queue. |
概括 -ArrayList vsLinkedList
该集合框架允许使用列表,树,地图和集合等数据结构。该列表是集合框架的接口。本文讨论了ArrayList和LinkedList之间的区别。ArrayList是一个扩展抽象列表并实现内部使用动态数组来存储数据元素的列表接口的类。linkedlist是一个扩展AbstractSequentionList的类,并在内部使用双重链接列表来存储数据元素。这就是ArrayList和LinkedList之间的区别。
参考:
1。Introduction to Linked List | Data Structure Tutorial | Studytonight.在这里可用
2.“ Java中的LinkedList - Javatpoint。”,重点,,,,在这里可用
3。“Java ArrayList class – javatpoint.”重点,,,,在这里可用
Santosh Kumar Sahusays
一篇不错的文章。感谢分享。
Pankaj Jainsays
The article is well written and informative too.
But I think could have also added a para saying how can you convert a list to an array under What is ArrayList.