Hi all,
Here's what Im trying to do:
I need to create an array of objects. I need to be able to reference them in order by using a for loop index or just sequentially. I have a class called 'employee', and a class for processing called 'collection'. I need to be able to create multiple instances of employee and shove them into an array. I also want to be able to read that array and pull properties of any instance in the array.
Here's what I've got so far:
public class Employee {
public String employeeName;
public String employeeSalary;
public String employeeDate;
}
import java.util.*;
public class Collection{
public static void main(String args[]) {
ArrayList aList = new ArrayList();
Object objArray[] = new Object[5];
for (int i = 0; i < 4; i++) {
Employee emp = new Employee();
emp.employeeName = "Fred";
emp.employeeSalary = "500000";
emp.employeeDate = "Jan 1";
//System.out.println(emp.employeeSalary);
objArray[i] = emp;
// aList.add(emp);
}
for (int i = 0; i < 4; i++) {
System.out.println(objArray[i]);
}
}
}
I've been trying multiple methods to create an object array to no avail. I believe that I should use an array list with an iterator, but havent found any substantial code online to help me do that.
Just a simple example of populating and reading properties from an object array would be awesome. Thanks!
