Hello,
See, if the following example helps you
Code:
class Ademo {
public static void main(String args[]) {
// create an array list
ArrayList arr = new ArrayList();
System.out.println(" size of arr: " +
arr.size());
// add elements to the array list
arr.add("C");
arr.add("A");
arr.add("E");
arr.add("B");
arr.add("D");
arr.add("F");
arr.add(1, "A2");
System.out.println("Size of arr after additions: " +
arr.size());
// display the array list
System.out.println("Contents of arr: " + arr);
// Remove elements from the array list
arr.remove("F");
arr.remove(2);
System.out.println("Size of arr after deletions: " +
arr.size());
System.out.println("Contents of arr: " + arr);
}
}
Bookmarks