It provides a linked-list data structure. It uses doubly linked-list to store elements. It extends the AbstractList class and implements List interface. We can use LinkedList class by importing java.util package.
Example:
import java.util.*;
public class ListDemo {
public static void main(String args[]) {
// create a linked list
LinkedList ll = new LinkedList();
// add elements to the linked list
ll.add("F");
ll.add("B");
ll.add("D");
ll.add("E");
ll.add("C");
ll.addLast("Z");
ll.addFirst("A");
ll.add(1, "A2");
System.out.println("Original contents of ll: " + ll);
// remove elements from the linked list
ll.remove("F");
ll.remove(2);
System.out.println("Contents of ll after deletion: "
+ ll);
}
}
0 Comment(s)