*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
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
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