how to use get index with integer arraylist java code example
Example 1: ArrayList set(int index E element) method in java
import java.util.ArrayList;
public class ArrayListSetMethodExample
{
public static void main(String[] args)
{
ArrayList<String> names = new ArrayList<String>(5);
names.add("vinay");
names.add("ajay");
names.add("vijay");
names.add("bharat");
names.add("dinesh");
System.out.println("ArrayList before using set() method: " + names);
System.out.println("ArrayList after using set() method: ");
names.set(2, new String("chandan"));
for(int a = 0; a < 5; a++)
{
System.out.println(names.get(a).toString());
}
}
}
Example 2: arraylist get value at index java
get(index);