public
E removeFirst()
Removes
and returns the first element from this list.
import java.util.*; class LinkedListRemoveFirst{ public static void main(String args[]){ LinkedList<Integer> myList; myList = new LinkedList<> (); /* Add Elements to myList */ myList.add(10); myList.add(20); myList.add(30); myList.add(10); System.out.println("Elements in myList are"); System.out.println(myList); System.out.println("\nCalling remove first"); myList.removeFirst(); System.out.println("\nElements in myList are"); System.out.println(myList); } }
Output
Elements in myList are [10, 20, 30, 10] Calling remove first Elements in myList are [20, 30, 10]
No comments:
Post a Comment