Listlist = new ArrayList<>(); list.add("apple"); list.add("banana"); list.add("cherry"); list.remove(1); // remove the element at index 1 System.out.println(list); // [apple, cherry]
ListThis code will remove the element 3 from the list and the output will be 3. The package library for this method is `java.util.LinkedList`.list = new LinkedList<>(); list.add(1); list.add(2); list.add(3); int removedElement = list.remove(2); // remove the element at index 2 System.out.println(removedElement); // 3