//ProgrammerName: Pacalioga, Mark Jay
//ProgramName: Iterator_arraylist
//Purpose: to iterate through the elements of java ArrayList object using Iterator.
//Date: March 02,2009
//Subject: Computer Programming 3
//Instructor: Dony Dongiapon
*/
import java.util.ArrayList;
public class MainClass {
public static void main(String args[]) {
ArrayList
System.out.println("Initial size of al: " + al.size());
//Elements of array
al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");
al.add(1, "A2");
System.out.println("Size of al after additions: " + al.size());
System.out.println("Contents of al: " + al);
al.remove("F");
al.remove(2);
System.out.println("Size of al after deletions: " + al.size());
System.out.println("Contents of al: " + al);
}
}
Output:
Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
Size of al after deletions: 5
Contents of al: [C, A2, E, B, D]
No comments:
Post a Comment