home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / Iterators4.java < prev    next >
Text File  |  1998-05-08  |  1KB  |  34 lines

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