1 Reply Latest reply: Nov 4, 2006 10:54 PM by 807607 RSS

    Passing a  Uninstantiated String Array to a method

    807607
      How do you pass a String array that hasn't been initiated to a method?
      the code:

      String stringarray[];
      fillUpArray(stringarray);

      the method:

      fillUpArray(String[] stringarray) {
      // ...
      }

      I know it's wrong - so how do I do it?
        • 1. Re: Passing a  Uninstantiated String Array to a method
          807607
          What you're trying to do doesn't make sense. You're trying to pass nothing to a method, and then have the method turn nothing into something.

          This might make sense (although might not be a good design) if Java used pass-by-reference...which it doesn't, as has been discussed endlessly on these forums.

          So what can you do?

          The best thing would probably be to have the method instantiate the array, and then return it as the return value:
          String[] someStringArray = createAndFillUpArray();
          By the way, when you post code (even imaginary code) please wrap it in [code][/code] tags, so it'll be easier to read.