home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-10 | 1.2 KB | 46 lines |
- import jgl.*;
-
- /**
- * Counting, finding, erasing.
- * <p>
- * @see jgl.HashMap
- * @version 1.1
- * @author ObjectSpace, Inc.
- */
-
- public class HashMap6
- {
- public static void main( String[] args )
- {
- HashMap map = new HashMap( true );
- map.add( "cat", "Meow" );
- map.add( "ape", "Squeak" );
- map.add( "ape", "Whoop" );
- map.add( "bat", "Squeak" );
- System.out.println( map );
-
- System.out.println( "map.count( ape ) = " + map.count( "ape" ) );
- HashMapIterator i = map.find( "ape" );
-
- if( i.equals( map.end() ) ) // A simpler way of saying this is: if( i.atEnd() ) ...
- {
- System.out.println( "Could not find dog." );
- }
- else
- {
- while( !i.atEnd() && i.key().equals( "ape" ) )
- {
- System.out.println( "Found " + i.get() );
- i.advance();
- }
- }
- System.out.println( "map.remove( ape ) = " + map.remove( "ape" ) );
- HashMapIterator j = map.find( "ape" );
- if( j.atEnd() ) // A simpler way of saying: if( j.equals( map.end() ) ) ...
- System.out.println( "Could not find ape." );
- else
- System.out.println( "Found " + j.get() );
- }
- }
-
-