Back To Java Collections Index
//Java program to demonstrate a LinkedList public class LinkedList_Impl { 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); cars.addFirst("Mazda"); System.out.println(cars); cars.addLast("Mazda"); System.out.println(cars); cars.removeFirst(); System.out.println(cars); cars.removeLast(); System.out.println(cars); // Use getFirst() to display the first item in the list System.out.println(cars.getFirst()); // Use getLast() to display the last item in the list System.out.println(cars.getLast()); }