import java.util.TreeMap;


/*
 * This class demonstrates the use of the TreeMap class.
 * @author Steven Castellucci, 2016
 * 
 */
public class TreeMapExample
{
	public static void main(String[] args)
	{
		// Initialize the collection.  The generic TreeMap<K,V> is
		// parameterized to TreeSet<String,String>
		TreeMap<String,String> map = new TreeMap<String,String>();
		
		// Add elements.
		// In this example, the keys are course codes and the values
		// are course titles.
		map.put("EECS1021", "???");
		map.put("CSE1020", "Intro to CS");
		map.put("PHYS1010", "Physics");
		map.put("EECS1021", "OOP from Sensors to Actuators");
			// Replaced the previous title for EECS1021.
		map.put("BIOL1000", "Biology I");
		
		// Remove elements.
		map.remove("CSE1020"); // remove key "CSE1020" and its value
		
		// Access elements.
		System.out.println("Value for key \"EECS1011\": " +
			map.get("EECS1011")); // "EECS1011" is not in the map
		System.out.println("Value for key \"PHYS1010\": " +
			map.get("PHYS1010"));
		
		// Iterate over all elements (keys).
		// Keys are in sorted order.
		System.out.println("Elements in collection (key, value):");
		for (String key : map.keySet())
		{
			System.out.println(key + ", " + map.get(key));
		}
	}
}
