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

  1. import jgl.*;
  2.  
  3. /**
  4.  * Counting, finding, erasing. 
  5.  * <p>
  6.  * @see jgl.HashMap
  7.  * @version 1.1
  8.  * @author ObjectSpace, Inc.
  9.  */
  10.  
  11. public class HashMap6
  12.   {
  13.   public static void main( String[] args )
  14.     {
  15.     HashMap map = new HashMap( true );
  16.     map.add( "cat", "Meow" );
  17.     map.add( "ape", "Squeak" );
  18.     map.add( "ape", "Whoop" );
  19.     map.add( "bat", "Squeak" );
  20.     System.out.println( map );
  21.  
  22.     System.out.println( "map.count( ape ) = " + map.count( "ape" ) );
  23.     HashMapIterator i = map.find( "ape" );
  24.  
  25.     if( i.equals( map.end() ) ) // A simpler way of saying this is: if( i.atEnd() ) ...
  26.       {
  27.       System.out.println( "Could not find dog." );
  28.       }
  29.     else
  30.       {
  31.       while( !i.atEnd() && i.key().equals( "ape" ) )
  32.         {
  33.         System.out.println( "Found " + i.get() ); 
  34.         i.advance();
  35.         }
  36.       }
  37.     System.out.println( "map.remove( ape ) = " + map.remove( "ape" ) );
  38.     HashMapIterator j = map.find( "ape" );
  39.     if( j.atEnd() ) // A simpler way of saying: if( j.equals( map.end() ) ) ...
  40.       System.out.println( "Could not find ape." );
  41.     else
  42.       System.out.println( "Found " + j.get() );
  43.     }
  44.   }
  45.  
  46.