Open In App

LinkedList get() Method in Java

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

In Java, the get() method of LinkedList is used to fetch or retrieve an element at a specific index from a LinkedList.

Example 1: Here, we use the get() method to retrieve an element at a specified index.


Output
[Geeks, for, Geeks, 10]
The element at index 3 is: 10

Syntax of Java LinkedList get() Method

public E get(int index)

  • Parameter: The parameter index is of integer data type that specifies the position or index of the element to be fetched from the LinkedList.
  • Return type: It return the element at the specified index.
  • Exception: It throws IndexOutOfBoundsException if the index is out of range (index < 0 or index >= size).

Example 2: Here, the get() method throw an exception IndexOutOfBoundsException, if we try to retrieve the element at an Invalid Index.


Output
Error: IndexOutOfBounds

Next Article

Similar Reads