home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / HashMap5.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 HashMap5
  15.   {
  16.   public static void main( String[] args )
  17.     {
  18.     HashMap map = new HashMap( true ); // allow duplicates
  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.