home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / HashMap2.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  1.3 KB  |  51 lines

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