LinkedListlist = new LinkedList<>(Arrays.asList(1, 2, 3, 4, 5)); list.removeFirstOccurrence(3); System.out.println(list); // [1, 2, 4, 5]
LinkedListlist = new LinkedList<>(Arrays.asList("apple", "banana", "orange", "pear")); list.remove(2); System.out.println(list); // [apple, banana, pear]
LinkedListThis code removes the last Node from the linked list. The Java collections framework provides the LinkedList class which contains several methods for Node removal. The package/library that contains this class is java.util.list = new LinkedList<>(Arrays.asList('a', 'b', 'c', 'd')); list.removeLast(); System.out.println(list); // [a, b, c]