public void add(int index,E element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
package com.candidjava.arrayList; import java.util.ArrayList; public class ArrayListAddIndex { public static void main(String[] args) { ArrayList<String> al=new ArrayList<String>(); al.add("candid"); al.add("mathan"); al.add("antony"); System.out.println(al); // adding element to 1st index position in arraylist al.add(1, "kumar"); System.out.println("After adding elements in specific index"); System.out.println(al); } }
OUTPUT
[candid, mathan, antony] After adding elements in specific index [candid, kumar, mathan, antony]