Programming Tutorials

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

By: Saravanan in Java Tutorials on 2009-10-03  

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





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)