add element at specific index in arraylist java code example
Example 1: arraylist insert at position
import java.util.ArrayList;
public class main{
public static void main(String[] args){
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(0);
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(0, 100);
for(int element : list){
System.out.print(list + ", ");
}
}
}
Example 2: arraylist adding at index
public void add(int index, E element)
arrlist.add(2,25);
Example 3: arraylist add at index
arrlist.add(2,25);