public
boolean offerFirst(E e)
Inserts
the specified element at the front of this list. Returns true once
the element added successfully.
import java.util.*; class LinkedListOfferFirst{ public static void main(String args[]){ LinkedList<Integer> myList; myList = new LinkedList<> (); /* Add Elements to myList */ myList.offerFirst(10); myList.offerFirst(20); myList.offerFirst(30); myList.offerFirst(40); System.out.println("Elements in myList are"); System.out.println(myList); } }
Output
Elements in myList are [40, 30, 20, 10]
No comments:
Post a Comment