import java.util.TreeMap;
import java.util.SortedMap;
import java.util.Iterator;
import java.util.*;

class TestJavaTreeMap {

public static void main(String[] args) {
  TreeMap<String, String> phoneBook = new TreeMap<String, String>();
  phoneBook.put("Smith, Jackson", "212-555-4444");
  phoneBook.put("Prichard, Marlene F.", "806-555-6565");
  phoneBook.put("Hayden, Sarah", "401-555-5220");
  phoneBook.put("Records, H.", "445-555-3241");
  phoneBook.put("Harrington, J. R.", "617-555-1962");
  phoneBook.put("Sousa, Keith", "252-555-0607");

  // Return all of the entries such that "H" <= key value < 
  // "I", in other words, all of the names that start with H
  SortedMap results = phoneBook.subMap("H","I");
           
  if (results.isEmpty()) {
    System.out.println("Sorry, no names beginning with H found.");
  } else {
    // Set up an iterator so we can print the entries in 
    // result
    Iterator<Map.Entry<String, String>> iter = 
       results.entrySet().iterator();
 
	 Map.Entry<String, String> entry;
    while (iter.hasNext()) {
      entry = iter.next();
      System.out.println(entry.getKey() + "\t: " + entry.getValue());
    }  // end while
  }  // end if


} // end main
} // end TestJavaTreeMap