I am trying to figure out how to create an array that contains objects
and not references to objects. I know how to do the latter, but not
the former. Any help is appreciated.
I have the following:
class ArrayTest extends Frame {
public static void main(String args[]) {
<snip>
Jones[] arr; // arr is an array of class Jones objects
arr = new Jones[5]; // allocate the array
// allocate the objects and fill the array with references to them
for (int i = 0; i < arr.length; i++) {
arr[i] = new Jones();
}
arr[0].type = 'c'; // for example
arr[0].group= 'g';
arr[0].args = "1, 4";
}
<more snipage>
}
public class Jones {
public String args;
public char group;
public char type;
}
and not references to objects. I know how to do the latter, but not
the former. Any help is appreciated.
I have the following:
class ArrayTest extends Frame {
public static void main(String args[]) {
<snip>
Jones[] arr; // arr is an array of class Jones objects
arr = new Jones[5]; // allocate the array
// allocate the objects and fill the array with references to them
for (int i = 0; i < arr.length; i++) {
arr[i] = new Jones();
}
arr[0].type = 'c'; // for example
arr[0].group= 'g';
arr[0].args = "1, 4";
}
<more snipage>
}
public class Jones {
public String args;
public char group;
public char type;
}
Comment