home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / examples / hashmap5.java < prev    next >
Encoding:
Java Source  |  1996-09-10  |  1.3 KB  |  52 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2.  
  3. import java.util.Enumeration;
  4. import jgl.*;
  5.  
  6. /**
  7.  * Accessing keys and values.
  8.  * <p>
  9.  * @see jgl.HashMap
  10.  * @version 1.1
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public class HashMap5
  15.   {
  16.   public static void main( String[] args )
  17.     {
  18.     HashMap map = new HashMap( true );
  19.     map.add( "cat", "Meow" );
  20.     map.add( "ape", "Squeak" );
  21.     map.add( "ape", "Whoop" );
  22.     map.add( "bat", "Squeak" );
  23.     System.out.println( "map = " + map );    
  24.     System.out.println();    
  25.  
  26.     System.out.println( "Enumerate the HashMap" );    
  27.     Enumeration e = map.elements();
  28.     while( e.hasMoreElements() )
  29.       System.out.println( e.nextElement() );
  30.     System.out.println();
  31.  
  32.     e = map.keys();
  33.     System.out.print( "map.keys() = " );
  34.     while( e.hasMoreElements() )
  35.       System.out.print( e.nextElement() + " " );
  36.     System.out.println();
  37.  
  38.     e = map.keys( "Squeak" );
  39.     System.out.print( "map.keys( Squeak ) = " );
  40.     while( e.hasMoreElements() )
  41.       System.out.print( e.nextElement() + " " );
  42.     System.out.println();
  43.  
  44.     e = map.values( "ape" );
  45.     System.out.print( "map.keys( ape ) = " );
  46.     while( e.hasMoreElements() )
  47.       System.out.print( e.nextElement() + " " );
  48.     System.out.println();
  49.     }
  50.   }
  51.  
  52.