0% found this document useful (0 votes)
5 views1 page

Java ArrayList Example and Usage

The document is a Java program demonstrating the use of an ArrayList. It shows how to add elements, including inserting an element at a specific index, and how to retrieve the size and elements of the ArrayList. The program prints the size of the ArrayList and each element in it.

Uploaded by

Rajasekar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Java ArrayList Example and Usage

The document is a Java program demonstrating the use of an ArrayList. It shows how to add elements, including inserting an element at a specific index, and how to retrieve the size and elements of the ArrayList. The program prints the size of the ArrayList and each element in it.

Uploaded by

Rajasekar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import [Link].

ArrayList;
public class ArrayListExample {
public static void main(String[] args) {
ArrayList<String> arlist=new ArrayList<String>();
//<E> it is return type of ArrayList
[Link]("First Element"); // adding element in ArrayList
[Link]("Second Element");
[Link]("Third Element");
[Link]("forth Element");
[Link]("fifth Element");
// add element with index for fix order
[Link](2, "Fixed Order of Element");
// [Link]() inform number of elements in ArrayList
[Link]("ArrayList Size :"+[Link]());
// get elements of ArrayList
for(int i=0;i<[Link]();i++)
{
[Link]("ArrayList Element "+i+" :"+[Link](i));
}
}
}

You might also like