Here is a Java Program to Add an element to specified index of Java ArrayList Example
Output of Above Java Program
ArrayList Contents :
1
INSERTED ELEMENT
2
3
import java.util.ArrayList; class AddElementToSpecifiedIndexArrayListExample { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); arrayList.add(1,"INSERTED ELEMENT"); System.out.println("ArrayList Contents : "); for(int index=0; index < arrayList.size(); index++) System.out.println(arrayList.get(index)); } }
Output of Above Java Program
ArrayList Contents :
1
INSERTED ELEMENT
2
3