LinkedList E peekLast() method Example Program


Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.peekLast() method retrieves, but does
 *              not remove, the last element of this list, or returns null if
 *              this list is empty.
 */
public class LinkedListPeekLast {
	public static void main(String[] args) {
		LinkedList list = new LinkedList();
		list.add("anandh");
		list.add("hari");
		list.add("vinoth");
		list.add("mohan");
		list.add("kamal");
		System.out.println("LinkedList:" + list);
		System.out.println("Last element of the list:" + list.peekLast());
	}
}

Output

LinkedList:[anandh, hari, vinoth, mohan, kamal]
Last element of the list:kamal

Explanation

public E peekLast()
Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.
Specified by:
peekLast in interface Deque<E>
Returns:
the last element of this list, or null if this list is empty
Since:
1.6


Related Post

Comments


©candidjava.com