All Packages  Class Hierarchy  Previous  Next  Index

Replacing Examples

Replacing 1 - Replacing an element in a native array of primitives, copy during replacement.


Replacing1 Example Code

// Copyright(c) 1996,1997 ObjectSpace, Inc.

import COM.objectspace.jgl.*;

/**
 * Replacing an element in a native array of primitives, copy during replacement.
 *
 * @see COM.objectspace.jgl.Replacing
 * @version 2.0.2
 * @author ObjectSpace, Inc.
 */

public class Replacing1
  {
  public static void main( String[] args )
    {
    int intArray[] = { 3, 6, 2, 1, 9, 6, 4, 2 };
    IntArray i = new IntArray( intArray );
    System.out.print( "Before: " );
    Printing.println( i.start(), i.finish() );
    Replacing.replace( i.start(), i.finish(), new Integer( 6 ), new Integer( 0 ) );
    System.out.print( "After: " );
    Printing.println( i.start(), i.finish() );

    Array array = new Array();
    array.add( "ape" );
    array.add( "cat" );
    array.add( "bat" );
    array.add( "cat" );
    Deque deque = new Deque();
    Replacing.replaceCopy( array, new InsertIterator( deque ), "cat", "emu" );
    System.out.println( "array = " + array + ", deque = " + deque );
    }
  }

Replacing1 Example Output

Before: ( 3, 6, 2, 1, 9, 6, 4, 2 )
After: ( 3, 0, 2, 1, 9, 0, 4, 2 )
array = Array( ape, cat, bat, cat ), deque = Deque( ape, emu, bat, emu )

All Packages  Class Hierarchy  Previous  Next  Index