ObjectSpace Homepage

JGL - The Generic Collection Library for Java
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Shuffling examples

Shuffling1 - Shuffling a JGL container.


Shuffling1 Example Code

// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;

/**
 * Shuffling a JGL container.
 *
 * @see com.objectspace.jgl.algorithms.Shuffling
 * @version 3.0.0
 * @author ObjectSpace, Inc.
 */

public class Shuffling1
  {
  public static void main( String[] args )
    {
    Array array = new Array();
    for ( int i = 0; i < 10; i++ )
      array.add( new Integer( i ) );
    System.out.println( "array = " + array );
    Shuffling.randomShuffle( array );
    System.out.println( "after shuffle = " + array );
    }
  }

Shuffling1 Example Output

array = Array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 )
after shuffle = Array( 2, 6, 3, 5, 1, 0, 8, 9, 4, 7 )

All Packages  Class Hierarchy  This Package  Previous  Next  Index