Sunday, March 1, 2009

/*Programmer: Miexie D. Tulid *Date started: March 02, 2009
 *Date ended: March 02, 2009
 *Description: A program that uses ArrayList and Iterator classes.*/

import java.util.Iterator;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.*;

public class ArrayListIteratorTest{
public static void main(String args[]){
Scanner scan=new Scanner(System.in);
String x="s";


ArrayList list=new ArrayList();



while(!x.equals("q")){
    x=JOptionPane.showInputDialog("Enter your favorite phrase. (Enter q to quit..)");
list.add(x);
}

System.out.println("Array List contents : ");
Iterator it = list.iterator();
while (it.hasNext()) {
String element = it.next();
if(!element.equals("q")){

 System.out.println(element);}
}  


}
}


Date: March 02, 2009

Things I've learned in this exercise.

  • ArrayList cannot hold premitive data types such as int.
  • In declaring an ArrayList index may not be specify.
  • Iterator class is the class that is used to manipulate ArrayList. 

No comments:

Post a Comment