home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / Iterators4.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  993 b   |  32 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. import COM.objectspace.jgl.*;
  3.  
  4. public class Iterators4
  5.   {
  6.   public static void main( String[] args )
  7.     {
  8.     Array array = new Array();
  9.     array.add( new Integer( 4 ) );
  10.     array.add( new Integer( 7 ) );
  11.     array.add( new Integer( 2 ) );
  12.     array.add( new Integer( 7 ) );
  13.     array.add( new Integer( 1 ) );
  14.     array.add( new Integer( 7 ) );
  15.     System.out.println( "array = " + array );
  16.  
  17.     // Obtain iterator positioned at first element.
  18.     ArrayIterator first = array.begin();
  19.  
  20.     // Obtain iterator positioned immediately after third element.
  21.     ArrayIterator last = array.begin();
  22.     last.advance( 3 );
  23.  
  24.     // Sort first three elements.
  25.     Sorting.sort( first, last );
  26.     System.out.println( "array = " + array );
  27.  
  28.     // Replace 7 with 0 in last three elements.
  29.     Replacing.replace( last, array.end(), new Integer( 7 ), new Integer( 0 ) );
  30.     System.out.println( "array = " + array );
  31.     }
  32.   }