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

By: Saravanan  

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



Archived Comments

1. very good
View Tutorial          By: amit at 2009-10-24 01:55:26

2. i like the example and it helped me understand the java data structure better now.
View Tutorial          By: Danny at 2009-10-23 02:09:06


Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial