Open In App

LinkedList element() Method in Java

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
1 Like
Like
Report

In Java, the element() method of the LinkedList class is used to retrieve the first element in the list without removing it. The first element of the LinkedList is known as the head.

Example 1: Here, we use the element() method to retrieve the first element of the LinkedList of Integers, without removing it.


Output
[10, 20, 30]
10

Syntax of Java LinkedList element() Method

public E element()

Return Value: This method returns the head of the list.

Example 2: Here, element() method throws NoSuchElementException when we try to get the head of an empty LinkedList.


Output
[A, B, C]
Head: A
Exception: java.util.NoSuchElementException

Similar Reads