package alphabetizewords;
import java.util.*;
public class Alphabetize {
public static void main(String[] args) {
//... Declare variables.
Scanner in = new Scanner(System.in);
ArrayListwords = 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()) {
words.add(in.next());
}
//... Sort the words.
Collections.sort(words);
//... Print the sorted list.
System.out.println("\n\nSorted words\n");
for (String word : words) {
System.out.println(word);
}
}
}
A java blog with a collection of examples and tutorials on Java and related technologies. (Under maintenance with continuous updates) Be in touch with java jazzle or k2java.blogspot.com.
Wednesday, September 22, 2010
Alphabetize.java (Arraylist example)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment