Sequences4 Example Code
// Copyright(c) 1996 ObjectSpace, Inc.
import jgl.*;
public class Sequences4
{
public static void main( String[] args )
{
Array array = new Array();
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
array.insert( 0, 9, "x" );
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
for( int i = 0; i < 2; i++ )
{
array.add( "x" ); // Causes reallocation of internal storage.
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
}
array.ensureCapacity( 1000 ); // Force reallocation of internal storage.
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
array.trimToSize(); // Reduce capacity to the minimum required.
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
}
}
Sequences4 Example Output
array = Array(), size = 0, capacity = 10
array = Array( x, x, x, x, x, x, x, x, x ), size = 9, capacity = 10
array = Array( x, x, x, x, x, x, x, x, x, x ), size = 10, capacity = 10
array = Array( x, x, x, x, x, x, x, x, x, x, x ), size = 11, capacity = 20
array = Array( x, x, x, x, x, x, x, x, x, x, x ), size = 11, capacity = 1000
array = Array( x, x, x, x, x, x, x, x, x, x, x ), size = 11, capacity = 11