ArrayList and LinkedList are both implementations of the List interface in Java. Both classes are asynchronous. But there are certain differences.
The following are the important differences between ArrayList and LinkedList methods.
gentlemen. No. | Key | ArrayList | LinkedList |
---|---|---|---|
1 | Internal implementation | ArrayList internally uses a dynamic array to store its elements . | LinkedList uses bidirectional linking to store a list of its elements. |
2 | Operation | ArrayList is slow because of the array Operation is slower. | Node-based LinkedList is faster because it doesn’t require as much bit shifting. |
3 | Implements | ArrayList only implements List. | LinkedList implements List and Queue. It can also act as a queue. |
4 | Access | ArrayList stores and accesses data faster. | LinkedList processes data faster. |
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class JavaTester { public static void main(String args[]) { List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); List<String> list1 = new LinkedList<>(); list1.add("A"); list1.add("B"); list1.add("C"); list1.add("D"); System.out.println(list); System.out.println(list1); } }
[A, B, C, D] [A, B, C, D]
The above is the detailed content of The difference between ArrayList and LinkedList in Java. For more information, please follow other related articles on the PHP Chinese website!