E
peekFirst()
Retrieves,
but does not remove, the first element of this deque.
import java.util.*;
class DequePeekFirst{
public static void main(String args[]){
Deque<Integer> myDeque = new LinkedList<Integer> ();
/* Add Elements to the myDeque */
myDeque.add(10);
myDeque.add(20);
myDeque.add(30);
myDeque.add(40);
System.out.println("Elements in the myDeque are " +myDeque);
System.out.println("\nRetrieving the First Element Of the Deque " + myDeque.peekFirst());
System.out.println("Elements in the myDeque are " +myDeque);
System.out.println("\nRetrieving the First Element Of the Deque " + myDeque.peekFirst());
System.out.println("Elements in the myDeque are " +myDeque);
}
}
Output
Elements in the myDeque are [10, 20, 30, 40] Retrieving the First Element Of the Deque 10 Elements in the myDeque are [10, 20, 30, 40] Retrieving the First Element Of the Deque 10 Elements in the myDeque are [10, 20, 30, 40]
1. returns
null if this deque is empty.
import java.util.*; class DequePeekFirstNull{ public static void main(String args[]){ Deque<Integer> myDeque = new LinkedList<Integer> (); System.out.println("Elements in the myDeque are " +myDeque); System.out.println("\nRetrieving the First Element Of the Deque " + myDeque.peekFirst()); } }
Output
Elements in the myDeque are [] Retrieving the First Element Of the Deque null
No comments:
Post a Comment