B
Bob Brown
Hi all,
I've been a programmer for yonks including with C++ and have recently
started using Java.
I know that when you pass classes as arguments to methods they are
references to the class. So this means that to return a completely
new instance of a class you must create an instance of the class
first. Is this correct?
Thus, if I want a method to return an array of Strings, then I must do
this by having something like an ArrayList returned. Thus I would
have
public void setStringArray(ArrayList tcStringArray) {
String lString=new String("one");
tcStringArray.add(lString);
....
}
public void dosomething() {
....
ArrayList lAL = new ArrayList();
setStringArray(lAL);
// convert lAL to an array of Strings now using toArray() but I'm
yet to work out how!
}
Given what I understand of references (and that Java doesn't use
pointers), this seems to be the only way you can create an array of
Strings in a called method. Am I correct? Is there a cleaner way to
arrange this? How does everybody like to write this?
Thankyou,
BB
I've been a programmer for yonks including with C++ and have recently
started using Java.
I know that when you pass classes as arguments to methods they are
references to the class. So this means that to return a completely
new instance of a class you must create an instance of the class
first. Is this correct?
Thus, if I want a method to return an array of Strings, then I must do
this by having something like an ArrayList returned. Thus I would
have
public void setStringArray(ArrayList tcStringArray) {
String lString=new String("one");
tcStringArray.add(lString);
....
}
public void dosomething() {
....
ArrayList lAL = new ArrayList();
setStringArray(lAL);
// convert lAL to an array of Strings now using toArray() but I'm
yet to work out how!
}
Given what I understand of references (and that Java doesn't use
pointers), this seems to be the only way you can create an array of
Strings in a called method. Am I correct? Is there a cleaner way to
arrange this? How does everybody like to write this?
Thankyou,
BB