Say I have something like this:
public void handle(ArrayList<Object> tasks) {
ArrayList<Object> results = new ArrayList<Object>();
for (int i = 0; i < tasks.size(); i++) {
results.set(i, tasks.get(i);
}
}
if I do the above I will get an error:
Index 0 out-of-bounds for length 0
so the temporary/dumb solution I have is to do:
for (int i = 0; i < tasks.size(); i++) {
results.add(null);
results.set(i, tasks.get(i);
}
but that is awful lol...how do we do this right with Java?