LinkedList E peekFirst()method Example Program


Retrieves, but does not remove, the first 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.peekFirst() method retrieves, but does
 *              not remove, the first element of this list, or returns null if
 *              this list is empty.
 */
public class LinkedListPeekFirst {
	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("First element of the list:" + list.peekFirst());
	}
}

Output

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

Explanation

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


Related Post

Comments


©candidjava.com