import java.util.Vector; class DoesNotWork { public static void main( String args[] ) { Vector empty = new Vector( 200 ); empty.setElementAt( "No one home", 2 ); } }
at DoesNotWork.main(All.java:8)
import java.util.Vector; class ThisWorks { public static void main( String args[] ) { Vector fillFirst = new Vector( 200 ); for ( int k = 0; k < 200; k++ ) fillFirst.addElement( null ); fillFirst.setElementAt( "Ok", 2 ); } }
import java.util.Vector; class ArrayAndObject { public static void main( String args[] ) { Vector test = new Vector( ); int[] grades = new int[25]; grades[10] = 4; test.addElement( grades ); int[] recoveredGrades = ( int[] ) test.elementAt( 0 ); System.out.println( recoveredGrades[ 10 ] ); recoveredGrades[ 2 ] = 12; System.out.println( grades[ 2 ] ); } }