By candid | Posted :
Jun 30, 2015
| Updated :
Jun 30, 2015
Retrieves, but does not remove, the head (first element) of this list.
Program
package com.candidjava;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :The java.util.LinkedList.element() method retrieves, but does
* not remove, the head (first element) of this list.
*/
public class LinkedListElement {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("vinoth");
list.add("kamal");
list.add("karthi");
list.add("anand");
System.out.println("LinkedList:" + list);
System.out.println("Head of list:" + list.element());
}
}
Output
LinkedList:[vinoth, kamal, karthi, anand]
Head of list:vinoth
Explanation
public E element()
Retrieves, but does not remove, the head (first element) of this list.