E
peekLast()
Retrieves,
but does not remove, the last element of this deque.
import java.util.*; class DequePeekLast{ 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 Last Element Of the Deque " + myDeque.peekLast()); System.out.println("Elements in the myDeque are " +myDeque); System.out.println("\nRetrieving the Last Element Of the Deque " + myDeque.peekLast()); System.out.println("Elements in the myDeque are " +myDeque); } }
Output
Elements in the myDeque are [10, 20, 30, 40] Retrieving the Last Element Of the Deque 40 Elements in the myDeque are [10, 20, 30, 40] Retrieving the Last Element Of the Deque 40 Elements in the myDeque are [10, 20, 30, 40]
1. returns
null if this deque is empty.
import java.util.*; class DequePeekLastNull{ 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 Last Element Of the Deque " + myDeque.peekLast()); } }
Output
Elements in the myDeque are [] Retrieving the Last Element Of the Deque null
No comments:
Post a Comment