/* TestList1.java CIS 160 David Klick 2009-12-01 Demonstration of ArrayList class. */ import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class TestList1 { public static void main(String[] args) { List words = new ArrayList(); Scanner in = new Scanner(System.in); String strIn = ""; do { System.out.print("Enter a word (ENTER to exit): "); strIn = in.nextLine(); if (strIn.length() > 0) { words.add(strIn); System.out.println(strIn + " added to set"); } } while (strIn.length() > 0); System.out.println("\nWords in list:"); for (String s : words) System.out.print(s + " "); System.out.println(); while (words.size() > 0) { System.out.println("Deleting first word in list"); words.remove(0); System.out.print("Words in list: "); for (String s : words) System.out.print(s + " "); System.out.println(); } } } /* Sample run: Enter a word (ENTER to exit): hi hi added to set Enter a word (ENTER to exit): there there added to set Enter a word (ENTER to exit): how how added to set Enter a word (ENTER to exit): are are added to set Enter a word (ENTER to exit): you you added to set Enter a word (ENTER to exit): hi hi added to set Enter a word (ENTER to exit): there there added to set Enter a word (ENTER to exit): Words in list: hi there how are you hi there Deleting first word in list Words in list: there how are you hi there Deleting first word in list Words in list: how are you hi there Deleting first word in list Words in list: are you hi there Deleting first word in list Words in list: you hi there Deleting first word in list Words in list: hi there Deleting first word in list Words in list: there Deleting first word in list Words in list: */