Simple java program to add an element to specified index of Java ArrayList
By: Saravanan 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
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Archived Comments
1. i like the example and it helped me understand the
View Tutorial By: Danny at 2009-10-23 02:09:06
2. very good
View Tutorial By: amit at 2009-10-24 01:55:26