import java.util.*;

// This code will only work with Java 1.2

public class SortStrings {

  public static void main (String [] args) {
    TreeSet strings = new TreeSet();
    String [] inputs = {"Bob","Alice","Ernie","Fred","Diane"};

    // Create tree by adding some elements
    for (int i=0; i<inputs.length; i++) {
      strings.add(inputs[i]);
    }
    
    // Make an array that is equivalent to the tree.
    // No sorting is performed here
    Object [] sortedStrings = (Object []) strings.toArray();
    for (int i=0; i<sortedStrings.length; i++) {
      System.out.print(sortedStrings[i] + " ");
    }
    System.out.println("");

    // Add an element and iterate over the tree w/o an array 
    strings.add("Chris");
    strings.remove("Fred");
    Iterator iter = strings.iterator();
    while (iter.hasNext()) {
      Object o = iter.next();
      System.out.print(o + " ");
    }
    System.out.println("");
  }
}

// paulmac@nautilus: java SortStrings
// Alice Bob Diane Ernie Fred 
// Alice Bob Chris Diane Ernie 

