public class ArrayList implements List
ü Used to create dynamic arrays
ü Extends AbstractList and implements List interface.
ü ArrayLists are created with an initial size.
ü As elements are added, size increases and the array expands.
Example:
import java.util.ArrayList;
public class ArrayListDemo
{
{
public static void main(String[] args)
{
{
//create an array list
ArrayList aL = new ArrayList();
//add element to the array list
aL.add("C");
aL.add("B");
aL.add("E");
aL.add("S");
aL.add(1, "B2");
System.out.println(aL.get(1));
//display the array list
System.out.println("Content of aL: " + aL);
aL.remove(2);
System.out.println(aL.get(2));
System.out.println("aL[0]: ");
}
}
}
0 comments :
Post a Comment