public
E peek()
Retrieves,
but does not remove, the head (first element) of this list.
import java.util.*; class LinkedListPeek{ public static void main(String args[]){ LinkedList<Integer> myList; myList = new LinkedList<> (); /* Add Elements to myList */ myList.offerLast(10); myList.offerLast(20); myList.offerLast(30); myList.offerLast(40); System.out.print("Head of myList is "); System.out.println(myList.peek()); } }
Output
Head of myList is 10
No comments:
Post a Comment