import java.util.ArrayList;
import java.util.Scanner;

/**
 * Shows how to use an ArrayList to store strings
 * as well as how to traverse a list, processing each element.
 *
 * @author Zach Tomaszewski
 * @version 05 Mar 2009
 */
public class A14Demo {

  public static void main(String[] args) {
    Scanner keybd = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<String>();

    //fill list with user entered lines
    boolean keepAsking = true;
    while (keepAsking) {
      System.out.print("Enter a line (or nothing to quit): ");
      String input = keybd.nextLine();
      if (input.equals("")) {
        //the sign to quit
        keepAsking = false;
      }else {
        lines.add(input); //add to end of list
      }
    }

    //now print out contents of list
    System.out.println("\nYou entered: ");
    for (int i = 0; i < lines.size(); i++) {
      System.out.println(lines.get(i));
    }
  }
}
