bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java LinkedList get() Method

❮ LinkedList Methods

Example

import java.util.LinkedList;
public class Main {
  public static void main(String[] args) {
    LinkedList<String> cars = new LinkedList<String>();
    cars.add("Volvo");
    cars.add("BMW");
    cars.add("Ford");
    cars.add("Mazda");
    System.out.println(cars.get(0));
  }
}

Definition and Usage

The get() method returns the item at a specified position in the list.

Syntax

public T get(int
index )

T refers to the data type of items in the list.

Parameter Values

ParameterDescription
indexRequired. Specifies the position of the item in the list.

Technical Details

Returns:The item at the specified position.
Throws:IndexOutOfBoundsException - If the index is less than zero, equal to the size of the list or greater than the size of the list.

Previous

Java LinkedList forEach() Method

Next

Java LinkedList getFirst() Method