/* TestList2.java CIS 160 David Klick 2009-12-01 Demonstration of LinkedList class. */ import java.util.LinkedList; import java.util.Scanner; public class TestList2 { public static void main(String[] args) { LinkedList words = new LinkedList(); 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.addLast(strIn); System.out.println(strIn + " added to list"); } } while (strIn.length() > 0); System.out.println("\nRemoving words from list:"); while (!words.isEmpty()) { System.out.println("Deleting: " + words.removeFirst()); } System.out.println("List empty"); } } /* Sample run: Enter a word (ENTER to exit): hi hi added to list Enter a word (ENTER to exit): there there added to list Enter a word (ENTER to exit): how how added to list Enter a word (ENTER to exit): are are added to list Enter a word (ENTER to exit): you you added to list Enter a word (ENTER to exit): hi hi added to list Enter a word (ENTER to exit): there there added to list Enter a word (ENTER to exit): Removing words from list: Deleting: hi Deleting: there Deleting: how Deleting: are Deleting: you Deleting: hi Deleting: there List empty */