Input
Output
import java.util.LinkedList; public class LinkedListExample { public static void main(String[] args) { LinkedList colors = new LinkedList<>(); // Add elements colors.add("Red"); colors.add("Green"); colors.add("Blue"); // Add first and last colors.addFirst("Black"); colors.addLast("White"); // Display elements for (String color : colors) { System.out.println(color); } // Access and modify System.out.println("First: " + colors.getFirst()); System.out.println("Last: " + colors.getLast()); // Remove elements colors.remove("Green"); colors.removeFirst(); // Display final list System.out.println("After removal: " + colors); } }