home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-30 | 1.3 KB | 51 lines |
- // Copyright(c) 1996,1997 ObjectSpace, Inc.
-
- import java.util.Enumeration;
- import COM.objectspace.jgl.*;
-
- /**
- * Accessing keys and values.
- *
- * @see COM.objectspace.jgl.HashMap
- * @version 2.0.2
- * @author ObjectSpace, Inc.
- */
-
- public class HashMap2
- {
- public static void main( String[] args )
- {
- HashMap map = new HashMap();
- map.add( "cat", "Meow" );
- map.add( "ape", "Squeak" );
- map.add( "dog", "Woof" );
- map.add( "bat", "Squeak" );
- System.out.println( "map = " + map );
-
- System.out.print( "Enumerate the HashMap: " );
- Enumeration e = map.elements();
- while ( e.hasMoreElements() )
- System.out.print( e.nextElement() + " ");
- System.out.println();
-
- System.out.print( "map.keys() = " );
- e = map.keys();
- while ( e.hasMoreElements() )
- System.out.print( e.nextElement() + " ");
- System.out.println();
-
- System.out.print( "map.keys( Squeak ) = " );
- e = map.keys( "Squeak" );
- while ( e.hasMoreElements() )
- System.out.print( e.nextElement() + " ");
- System.out.println();
-
- System.out.print( "map.values( bat ) = " );
- e = map.values( "bat" );
- while ( e.hasMoreElements() )
- System.out.print( e.nextElement() + " ");
- System.out.println();
- }
- }
-
-