remove() method

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>();
	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

Leave a Comment

Follow us on Instagram & watch the latest videos on YouTube. Click below social icons to visit our Instagram & YouTube profiles.