remove() method: This remove in java method is used retrieve and remove the first element from LinkedList. Its return type is E.
E remove();
Where E is the element that you want to remove from the LinkedList.
throws NoSuchElementException if this list is empty.
import java.util.LinkedList; public class ExampleOfLinkedList { public static void main(String[] args) { LinkedList<String> listOfNames = new LinkedList<String>(); listOfNames.add("JAVA"); listOfNames.add("GOAL"); listOfNames.add("RAVI"); String removedName = listOfNames.remove(); System.out.println("The element is removes successfully = "+removedName); for(String name : listOfNames) { System.out.println("Names from list = "+name); } } }
Output: The element is removes successfully = JAVA
Names from list = GOAL
Names from list = RAVI