home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / HashMap6.java < prev    next >
Text File  |  1997-07-30  |  1KB  |  45 lines

  1. import COM.objectspace.jgl.*;
  2.  
  3. /**
  4.  * Counting, finding, erasing.
  5.  *
  6.  * @see COM.objectspace.jgl.HashMap
  7.  * @version 2.0.2
  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 ); // allow duplicates
  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: 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: 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.