Return from a private method?

I have a simple question regarding design of private methods. If I have private methods within my class that are performing tasks, such as populating ArrayLists for use within the class only, is it acceptable practice to return the ArrayLists from the private method that is building them? Or should I simply declare each ArrayList I am building as an instance variable and the private method sets the instance variable?

For instance, should it be this way:

publicvoid runBatch(){

List list = this.buildList();

this.searchList(list);

}

private List buildList(){

List methodList =new ArrayList();

// build logic

return methodList;

}

Or:

List list =new ArrayList();

publicvoid runBatch(){

this.buildList();

this.searchList(list);

}

privatevoid buildList(){

list.add("test1");

list.add("test1");

}

[1549 byte] By [Bart69a] at [2007-11-27 4:35:03]
# 1

Post 69 from Bart69 -- time to buy a lottery ticket?

The real difference between 1 and 2 is that 2 has list as a field or state in the object,

while in 1, list is a local variable. Does your object need to remember

list even when the object's code isn't being executed? (I.e., in between calls)

If it doesn't need to remember list, don't make it a field. That is just being lazy --

local values should be passed as parameters and returned as return values,

not stored in fields for convenience.

Hippolytea at 2007-7-12 9:45:03 > top of Java-index,Java Essentials,New To Java...
# 2
Wow, I didn't even notice that. I'll play 069 tonight and watch my immaturity pay dividends.Anyway, that makes sense. I will keep all of that in mind. Thank you for your help.
Bart69a at 2007-7-12 9:45:03 > top of Java-index,Java Essentials,New To Java...