VOOZH about

URL: https://www.geeksforgeeks.org/java/linkedlist-get-method-in-java/

⇱ LinkedList get() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList get() Method in Java

Last Updated : 11 Jul, 2025

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
Comment