home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / HashMap5.java < prev    next >
Text File  |  1998-05-08  |  1KB  |  50 lines

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