Java List.get(int index)

Syntax

List.get(int index) has the following syntax.

E get(int index)

Example

In the following code shows how to use List.get(int index) method.


import java.util.ArrayList;
import java.util.List;
//from w ww.  j a va  2  s . c  o m
public class Main {
  public static void main(String args[]) throws Exception {

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("B");
    list.add("C");

    System.out.println(list.get(2));

  }
}

The code above generates the following result.