import java.util.LinkedList; public class LinkedListExample { public static void main(String[] args) { LinkedListanimals = new LinkedList (); // Add elements to the LinkedList animals.add("Dog"); animals.add("Cat"); animals.add("Rabbit"); // Add an element to the end of the LinkedList animals.addLast("Mouse"); System.out.println("LinkedList: " + animals); } }
LinkedList: [Dog, Cat, Rabbit, Mouse]
import java.util.LinkedList; public class LinkedListExample { public static void main(String[] args) { LinkedListlist = new LinkedList (); // Add null to the end of the LinkedList list.addLast(null); System.out.println("LinkedList: " + list); } }
LinkedList: [null]Package library: java.util