/**
 * A sample program to show how to use HashMap class.
 * @author Kiminori Matsuzaki.
 */

import java.io.*;

/*
 * To use HashMap class, you need to import java.util.HashMap
 */
import java.util.*;

/**
 * HashMap provides many methods among which important methods are as
 * follows
 *  - put( Object key, Object value );
 *  - containsKey( Object key );
 *  - get( Object key ):
 *  - remove( Object remove );
 */
class HashMapSample {
  public static void main( String[] args ) {
    /* create an empty hashmap. */
    HashMap hashmap = new HashMap( );

    /* put pairs of keys and values. */
    hashmap.put( "1st item", "1st value" );
    hashmap.put( "2nd item", "2nd value" );

    /* check whether the hashmap contains a key */
    System.out.println( "Does the key \"1st item\" exist? " +
			hashmap.containsKey( "1st item" ) );
    System.out.println( "Does the key \"3rd item\" exist? " +
			hashmap.containsKey( "3rd item" ) );

    /* get the value by specifying the key */
    System.out.println( "The value associated to \"2nd item\" is: " +
			( String ) hashmap.get( "2nd item" ) );

    /* If you put pair whose key is already set, then the old data
     * will be overwritten */
    hashmap.put( "2nd item", "new 2nd value" );
    System.out.println( "The value associated to \"2nd item\" is: " +
			( String) hashmap.get( "2nd item" ) );

  }
}  

