I have a static arrayList used elsewhere in my code called jobsList. I would like to add elements to it using a static method. For some reason it is overwriting the jobList so that every time I add an element, the 1st element is the element I just added and nothing else. As in, no other elements are ever added. Relevant code below:
public static ArrayList<Job> jobList = null;
public JobSchedule() {
jobList = new ArrayList<Job>(10);
}
public static Job addJob(int time) {
System.out.println("Adding job " + time);
Job j = new Job(time);
jobList.add(j);
System.out.println("Current joblist size: " + jobList.size());
System.out.println("First element: " + jobList.get(0).weight);
return j;
}
The output from the printlines looks like this:
Adding job 8
Current joblist size: 1
First element: 8
Adding job 5
Current joblist size: 1
First element: 5
Ideally each time I add it should increment the size and put the job at the correct index, so I'm not sure why the arraylist is being overwritten.
static ArrayList<Job> jobList....public JobSchedule() { jobList = new ArrayList<Job>(10); }, something looks not right here.