removeFirst() method

removeFirst() method: This removefirst Java method is used to retrieve and remove the first element from LinkedList. Its return type is E.

E removeFirst();

Where, E is the element which you want to remove from the LinkedList.

import java.util.LinkedList;
public class ExampleOfLinkedList 
  public static void main(String[] args) 
	LinkedList<String> listOfNames = new LinkedList<String>();
	String removedName = listOfNames.removeFirst();
	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.