Java Collection Tutorial - 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;
/*www.  j av  a  2  s  . com*/
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.