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

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2.  
  3. import java.util.Enumeration;
  4. import COM.objectspace.jgl.*;
  5.  
  6. /**
  7.  * Construction, enumeration, access, pushing, popping.
  8.  *
  9.  * @see COM.objectspace.jgl.Array
  10.  * @version 2.0.2
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public class Array1
  15.   {
  16.   public static void main( String[] args )
  17.     {
  18.     Array array = new Array();
  19.     array.pushBack( "bat" );
  20.     array.add( "cat" );
  21.     array.pushFront( "ape" );
  22.     System.out.println( array );
  23.     System.out.println();
  24.  
  25.     System.out.println( "Enumerate the Array" );
  26.     Enumeration e = array.elements();
  27.     while ( e.hasMoreElements() )
  28.       System.out.println( e.nextElement() );
  29.     System.out.println();
  30.  
  31.     System.out.println( "Iterate through the Array" );
  32.     for ( ArrayIterator i = array.begin(); !i.equals( array.end() ); i.advance() )
  33.       System.out.println( i.get() );
  34.     System.out.println();
  35.  
  36.     System.out.println( "Demonstrate access" );
  37.     System.out.println( "array.at( 0 ) = " + array.at( 0 ) );
  38.     System.out.println( "array.front() = " + array.front() );
  39.     System.out.println( "array.at( 2 ) = " + array.at( 2 ) );
  40.     System.out.println( "array.back() = " + array.back() );
  41.     System.out.println();
  42.  
  43.     System.out.println( "Demonstrate modification" );
  44.     array.put( 1, "fox" );
  45.     System.out.println( array );
  46.  
  47.     array.popFront();
  48.     System.out.println( "After popFront() = " + array );
  49.  
  50.     array.popBack();
  51.     System.out.println( "After popBack() = " + array );
  52.     }
  53.   }
  54.