1 Answer
1

public class HeavyWorkBatch {
ArrayList<File> myList = new ArrayList<>();
public void AddToBatch(File f) {
myList.add(f);
}
public void DoHeavyWork() {
for (File f: myList) {
/// ...
}
}
}
// Note there is a conspicuous lack of cleanup...
// What happens when AddToBatch is called again after DoHeavyWork?
// Is the class reusable so that DoHeavyWork should clear the ArrayList?

However, having the collection internal is not necessary based on the sample given. And given the questions I posed above, you could simplify it to just this:

public static void DoHeavyWork(File f) {
/// ...
}

And then build the list separately, and iterate separately from doing the work. That way, your file operation can be reasoned about and reused separately from the collection. Because building a batch is a separate concern from operating on a file.

myList.forEach((file) -> {
HeavyWork.DoHeavyWork(file);
});

If you need to build a batch from a larger list, then you could do so in other ways.