FileDocCategorySizeDatePackage
HashMap1.javaAPI DocExample1946Sat Sep 12 03:01:00 BST 1998None

HashMap1

public class HashMap1 extends Object
Construction, enumeration, access, rejection of duplicates.
see
com.objectspace.jgl.HashMap
version
3.0.0
author
ObjectSpace, Inc.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    HashMap map = new HashMap();
    map.add( new Integer( 2 ), "two" );
    map.add( new Integer( 4 ), "four" );
    System.out.println( map );
    System.out.println();

    System.out.println( "Enumerate the HashMap" );
    Enumeration e = map.elements();
    while ( e.hasMoreElements() )
      System.out.println( e.nextElement() );
    System.out.println();

    System.out.println( "Iterate through the HashMap" );
    for ( HashMapIterator i = map.begin(); !i.atEnd(); i.advance() )
      System.out.println( i.get() + ", key = " + i.key() + ", value = " + i.value() );
    System.out.println();

    System.out.println( "Demonstrate access" );
    System.out.println( "map.get( 2 ) = " + map.get( new Integer( 2 ) ) );
    System.out.println( "map.get( 5 ) = " + map.get( new Integer( 5 ) ) );
    System.out.println( "map = " + map );
    System.out.println();

    System.out.println( "Show that duplicates cannot be added." );
    Object value = map.add( new Integer( 8 ), "eight" );
    if ( value != null )
      System.out.println( "Could not add 8." );
    else
      System.out.println( "Added 8." );
    System.out.println( "map = " + map );

    value = map.add( new Integer( 4 ), "FOUR" );
    if ( value != null )
      System.out.println( "Could not add 4." );
    else
      System.out.println( "Added 4." );
    System.out.println( "map = " + map );
    System.out.println();

    System.out.println( "Demonstrate modification" );
    map.put( new Integer( 4 ), "FOUR" );
    System.out.println( "map = " + map );