I was reading this and wondered whether there is a particular reason
for having methods which fill a pre-existing array or object with
data, rather than returning an instance of the object or data.
These are two alternative ways.
Providing a object to be populated as parameter of a method has some advantages when (there are of course others):
1) you want to provide to the method an object with a state defined by the client and not in a generic or pristine state defined in the invoked method.
Without passing an instance of it as parameter, you cannot do it.
2) you want to spare memory consumption. If you have already an object to pass it as parameter, why creating a new one in the invoked method ?
3) you have multiple objects to value in the method but a method can only return a single object.
Imagine you want to populate 3 lists in the implementation.
For example you could invoke poupulateList(myList, myOtherList, myAgainOtherList);
with this implementation :
public void populateList(List<String> list, List<String> myOtherList, List<String> myAgainOtherList){
....
}
Without passed the objects as parameters you are forced to introduce a custom class that contains all these objects and to define it as the returned type of the method.