import java.util.*;

public class MapSetExample {

  static public void main(String[] args) {
    // create some data for the keys, use names
    String[] name = {"Smith, Jackson",
                     "Prichard, Marlene",
                     "Hayden, Sarah",
                     "Records, Hal",
                     "Prichard, Marlene"};

    // create corresponding values for the keys
    String[] phone = {"212-555-4444",
                      "806-555-6565",
                      "401-555-5220",
                      "445-555-3241",
                      "715-555-9087"};

    // Declare a map to contain the names and phone numbers 
    HashMap<String, String> phoneBook = new HashMap<String, String>();
 
    // Insert the names and phone number pairs into the map.
    // replace original entry.
    for (int i=0; i<name.length; i++) {
      phoneBook.put(name[i], phone[i]);
    } // end for
 
    // print the contents of the map  
    Set<Map.Entry<String,String>> resultSet = phoneBook.entrySet();
    Iterator<Map.Entry<String,String>> iter = resultSet.iterator();
    Map.Entry<String, String> entry; 
 
    while (iter.hasNext()) {
      entry = iter.next();
    } // end while
    System.out.println("\n");

    // Retrieve a map value
    System.out.println("Search for " + name[2]);
    System.out.println("  - phone number is " + 
                       phoneBook.get(name[2]));

    TreeMap<String, String> phoneBookSorted = 
       new TreeMap<String, String>();
 
    // insert the names and phone number pairs into the map
    // replace original entry
    for (int i=0; i<name.length; i++) {
      phoneBookSorted.put(name[i], phone[i]);
    } // end phone
    System.out.println("\n");
 
    // print the contents of the map
    Set<Map.Entry<String,String>> sortedSet = 
        phoneBookSorted.entrySet();
    iter = sortedSet.iterator();
    while (iter.hasNext()) {
      entry = iter.next();
    } // end while
  } // end main
} // // end MapSetExample
