LinkedList
TheLinkedList class is almost identical to the ArrayList:import java.util.LinkedList;public class Main {
public static void main(String[] args) {
LinkedList cars = new LinkedList();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println(cars);
}
}
ArrayList vs LinkedList
- ArrayList: Uses a dynamic array. Fast for storing and accessing data. Slow for manipulation (add/remove) in the middle.
- LinkedList: Uses a doubly linked list. Fast for manipulation. Slower for accessing data.