Best way to create an array of Strings in a called method

From: Bob Brown (privatemailinglists_at_yahoo.com)
Date: 06/30/04


Date: 30 Jun 2004 07:41:47 -0700

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



Relevant Pages

  • Re: How do you use another class file... Seriously
    ... >>application as thats the entry point to your program. ... The mainmethod must be static, not return a value, and take an array ... of strings. ... cannot do this in Java 1.1. ...
    (comp.lang.java.programmer)
  • Re: how to "translate" dynamic array in FORTRAN 90 to Java code?
    ... strings into an array by overwriting enough array elements to ... I don't think that's the way Fortran character variables work... ... is an array of 10 strings each 15 characters long. ... chararray in Java should be a very nice equivalent of the character ...
    (comp.lang.java.programmer)
  • Re: Returning String Array from Delphi DLL to Java
    ... > example of reutrning an array of Strings back to Java. ... There is an example of returning an array here: ... and my corresponding Delphi code is this: ...
    (borland.public.delphi.nativeapi)
  • Re: Iterating through the attributes of a structure
    ... > Thankfully back on the Delphi after a couple of months in hell ... > doing Java and C!! ... If all the AttrX attributes are the same type, why not use and array ... If there are other items besides the attribute strings, ...
    (comp.lang.pascal.delphi.misc)
  • Re: CUP/LEX has limitations
    ... Java has a limit of 64k code per method (you, ... Java's array initialization is no help. ... strings in the source and then unpack the strings at run time. ...
    (comp.compilers)