Simple java program to add an element to specified index of Java ArrayList

By: Saravanan Viewed: 153189 times  Printer Friendly Format    


In this Tutorial we are going to see how to add an element to specified index
of Java ArrayList.

//This is a program for add an element to specified index of Java ArrayList

import java.util.ArrayList;

public class AddExample
{
public static void main(String[] args)
{
ArrayList<String> alist = new ArrayList<String>();
alist.add("2");
alist.add("7");
alist.add("9");

alist.add(1, "INSERTED");
for (String s: alist)
System.out.println(s);
}
}


Output:

2
INSERTED
7
9


Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial