how to get values from arraylist in java code example
Example 1: how to select a element in an arraylist java
import java.util.ArrayList;
import java.util.Arrays;
public class ArrayListExample
{
public static void main(String[] args)
{
ArrayList<String> list = new ArrayList<>(Arrays.asList("alex", "brian", "charles", "dough"));
String firstName = list.get(0);
String secondName = list.get(1);
System.out.println(firstName);
System.out.println(secondName);
}
}
Example 2: java first index of an arraylist
ArrayList<Type> array = new ArrayList<Type>();
System.out.printLn(array[0]);