C4.java

import java.util.*;

/**
Simple example of HashMap and its corresponding sets.
*/
class C4
{
    public static void main(String argv[])
    {
        HashMap x;
        Set keys,entries;
        Collection values;
        Iterator y;

        x = new HashMap();
        x.put("a01","Tufted titmouse");
        x.put("a02","White-breasted nuthatch");
        x.put("a03","Red-breasted nuthatch");
        x.put("a04","Downy woodpecker");
        x.put("a05","Hairy woodpecker");
        x.put("a06","Red-bellied woodpecker");
        x.put("a07","Junco");
        x.put("a08","House finch");
        x.put("a09","House sparrow");
        x.put("a10","Bluejay");
        x.put("a11","Cardinal");
        x.put("a12","Ruby-throated hummingbird");
        x.put("a13","Sparrow");
        x.put("a14","Carolina wren");
        x.put("a15","Black-capped chickadee");
        x.put("a16","Robin");
        x.put("a17","Cowbird");
        x.put("a18","Catbird");
        x.put("a19","Mockingbird");
        x.put("a20","Grackle");
        x.put("a21","Crow");
        x.put("a22","Red-winged blackbird");
        x.put("a23","Goldfinch");

        System.out.println("\nThe keys from the original set.");
        keys = x.keySet();
        y = keys.iterator();
        while (y.hasNext()) {
            Object z = y.next();
            System.out.println("   " + z);
            }

        System.out.println("\nThe values from the original set.");
        values = x.values();
        y = values.iterator();
        while (y.hasNext()) {
            Object z = y.next();
            System.out.println("   " + z);
            }

        System.out.println("\nThe entries from the original set.");
        entries = x.entrySet();
        y = entries.iterator();
        while (y.hasNext()) {
            Map.Entry z = (Map.Entry)(y.next());
            System.out.println("   " + 
                z.getKey() + " = " + z.getValue());
            }
    }
}