// Demonstrate ArrayList. import java.util.*; class ArrayListDemo { public static void main(String args[]) { // create an array list ArrayList al = new ArrayList(); System.out.println("Initial size of al: " + al.size()); // add elements to the array list al.add("C"); al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); al.add("H"); al.add(2, "A2"); System.out.println("Size of al after additions: " + al.size()); // display the array list System.out.println("Contents of al: " + al); // Remove elements from the array list al.remove("F"); al.remove(6); System.out.println("Size of al after deletions: " + al.size()); System.out.println("Contents of al: " + al); } }
Search Java Programs
Showing posts with label ArrayList(). Show all posts
Showing posts with label ArrayList(). Show all posts
Tuesday, January 26, 2010
How to use ArrayList in Java
Subscribe to:
Posts (Atom)