Wednesday, September 22, 2010 (Arraylist example)

package alphabetizewords;

import java.util.*;

public class Alphabetize {

public static void main(String[] args) {
//... Declare variables.
Scanner in = new Scanner(;
ArrayList words = new ArrayList();

//... Read input one word at a time.
System.out.println("Enter words. End with EOF (CTRL-Z then Enter)");
System.out.println(" or click Close Input in NetBeans.");

//... Read input one word at a time, adding it to an array list.
while (in.hasNext()) {

//... Sort the words.

//... Print the sorted list.
System.out.println("\n\nSorted words\n");
for (String word : words) {

No comments:

Post a Comment