/* Author : Michael Robinson Program : ObjectsArraysArrayLists.java Purpose : - To create an Array of Objects and copy it into an ArrayList of Objects - From a text file load Objects into an Array and display them Updated : July 3nd, 2099 */ import java.util.ArrayList; public class ObjectsArraysArrayLists { public static void arrayListObjects( Object arrayObjects[] ) { //notice that we have accepted and array of Object data //type containing multiple data types System.out.println( "\n Copying an array of Objects into" + " an ArrayList of Objects" ); //create an ArrayList of Objects data type ArrayList arrayListObjects = new ArrayList(); //copy the elements in an array of Objects to an ArraList of //Objects and display them int x = 0; for( x = 0; x < arrayObjects.length; x++ ) { arrayListObjects.add( arrayObjects[x] ); System.out.println( " arrayListObjects( " + x + " ) = "+ arrayListObjects.get(x) ); } }//end public static void arrayListObjects(Object arrayObjects[]) public static void arrayOfObjects() { System.out.println( "\n Processing an array of Objects" ); //create an array of Objects. Notice that they are made with //multiple data types Object arrayObjects[] = { 1, "one", 1.4, 0.25, "COP2250", "Java Language", 100 }; //display elements in an array to Objects for( int x = 0; x < arrayObjects.length ; x++ ) { System.out.println( " arrayObjects[" + x + "] = " + arrayObjects[x] ); } //call a method passing an array of Objects arrayListObjects( arrayObjects ); }//end public static void arrayOfObjects() public static void main( String arg[] ) { arrayOfObjects(); }//end public static void main( String arg[] ) }//end public class ObjectsArraysArrayLists