Container 1 - No Description Available
Container 2 - No Description Available
Container 3 - No Description Available
Container 4 - No Description Available
Container 5 - No Description Available
Container 6 - No Description Available
Container 7 - No Description Available
Container 8 - No Description Available
Container 9 - No Description Available
Container 10 - No Description Available
Container1 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container1 { public static void main( String[] args ) { Array array = new Array(); array.add( "triangle" ); array.add( "square" ); array.add( "pentagon" ); array.add( "hexagon" ); System.out.println( "array = " + array ); System.out.println( "array.size() = " + array.size() ); System.out.println( "array.empty() = " + array.isEmpty() ); array.clear(); System.out.println( "after array is cleared..." ); System.out.println( "array.size() = " + array.size() ); System.out.println( "array.empty() = " + array.isEmpty() ); } }
array = Array( triangle, square, pentagon, hexagon ) array.size() = 4 array.empty() = false after array is cleared... array.size() = 0 array.empty() = true Container1 Example Output
Container2 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; import java.util.Enumeration; public class Container2 { public static void main( String[] args ) { Array array = new Array(); array.add( "triangle" ); array.add( "square" ); array.add( "pentagon" ); array.add( "hexagon" ); Enumeration iterator = array.elements(); while( iterator.hasMoreElements() ) System.out.println( iterator.nextElement() ); } }
triangle square pentagon hexagon Container2 Example Output
Container3 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container3 { public static void main( String[] args ) { Array array1 = new Array(); array1.add( "triangle" ); array1.add( "square" ); array1.add( "pentagon" ); System.out.println( "array1 = " + array1 ); // Illustrate copy construction. Array array2 = new Array( array1 ); System.out.println( "array2 = " + array2 ); System.out.println( "array1.equals( array2 ) = " + array1.equals( array2 ) ); // Illustrate assignment using copy(). Array array3 = new Array(); array3.add( "heptagon" ); array3.add( "octagon" ); System.out.println( "before copy, array3 = " + array3 ); array3.copy( array1 ); System.out.println( "after copy, array3 = " + array3 ); // Illustrate cloning. Array array4 = (Array) array1.clone(); System.out.println( "array4 = " + array4 ); } }
array1 = Array( triangle, square, pentagon ) array2 = Array( triangle, square, pentagon ) array1.equals( array2 ) = true before copy, array3 = Array( heptagon, octagon ) after copy, array3 = Array( triangle, square, pentagon ) array4 = Array( triangle, square, pentagon ) Container3 Example Output
Container4 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container4 { public static void main( String[] args ) { Array array1 = new Array(); array1.add( "ape" ); array1.add( "bat" ); array1.add( "cat" ); Array array2 = new Array(); array2.add( "red" ); array2.add( "blue" ); // Illustrate swapping. System.out.println( "array1 = " + array1 + ", array2 = " + array2 ); array1.swap( array2 ); System.out.println( "array1 = " + array1 + ", array2 = " + array2 ); } }
array1 = Array( ape, bat, cat ), array2 = Array( red, blue ) array1 = Array( red, blue ), array2 = Array( ape, bat, cat ) Container4 Example Output
Container5 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container5 { public static void main( String[] args ) { Array Array = new Array(); Array.add( new Integer( 2 ) ); Array.add( new Boolean( false ) ); Array.add( new Character( 'x' ) ); Array.add( new Float( 3.14F ) ); System.out.println( "Array = " + Array ); } }
Array = Array( 2, false, x, 3.14 ) Container5 Example Output
Container6 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; import Company; public class Container6 { public static void main( String[] args ) { Company company1 = new Company( "ObjectSpace" ); Company company2 = new Company( "Sun Microsystems" ); HashMap headquarters = new HashMap(); headquarters.put( company1, "Texas" ); headquarters.put( company2, "California" ); String location = (String) headquarters.get( company1 ); System.out.println( "The headquarters of " + company1 + " are in " + location ); } }
The headquarters of Company( ObjectSpace ) are in Texas Container6 Example Output
Container7 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container7 { public static void main( String[] args ) { Array array = new Array(); array.add( "ape" ); array.add( "cat" ); try { Object object = array.at( 5 ); } catch( IndexOutOfBoundsException exception ) { System.out.println( "Caught " + exception ); } } }
Caught java.lang.IndexOutOfBoundsException: Attempt to access index 5 when valid range is 0..1 Container7 Example Output
Container8 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container8 { public static void main( String[] args ) { Array array = new Array(); try { Object object = array.front(); } catch( InvalidOperationException exception ) { System.out.println( "Caught " + exception ); } } }
Caught jgl.InvalidOperationException: Array is empty Container8 Example Output
Container9 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container9 { public static void main( String[] args ) { try { Array array = new Array( -2 ); } catch( IllegalArgumentException exception ) { System.out.println( "Caught " + exception ); } } }
Caught java.lang.IllegalArgumentException: Attempt to create an Array with a negative size Container9 Example Output
Container10 Example Code
// Copyright(c) 1996 ObjectSpace, Inc. import jgl.*; public class Container10 { public static void main( String[] args ) { int ints[] = { 3, -1, 2, 0, -6 }; IntArray intArray = new IntArray( ints ); // Construct adapter class. System.out.println( "unsorted native int array = " + intArray ); Sorting.sort( intArray ); // Sort native array. System.out.print( "sorted = " ); for( int i = 0; i < ints.length; i++ ) System.out.print( ints[ i ] + " " ); System.out.println(); } }
unsorted native int array = int[]( 3, -1, 2, 0, -6 ) sorted = -6 -1 0 2 3 Container10 Example Output