How to Access an Item in an ArrayList in Java


In this example we will show the method to access an item in an ArrayList in Java.

Source Code

package com.beginner.examples;

import java.util.ArrayList;

public class AccessArrayList { 
  public static void main(String[] args) { 
    ArrayList strs = new ArrayList(); // ArrayList
    strs.add("a");
    strs.add("b");
    strs.add("c");
    System.out.println(strs.get(1)); // access an item in an ArrayList
  } 
}

Output:

b

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments