How to pass two dimensional array in Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aeo3
    New Member
    • Jul 2007
    • 29

    How to pass two dimensional array in Java

    Hi all,
    I am trying to pass a two dimensional in java but there a problem in this function
    Code:
        public static void doOutput(String args[], double vector[][40])
    Please what is the problem in this line
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    As far as I know, you cannot pass size of dimensions!
    And it's better to use different syntax, not C++ syntax.

    So just write
    Code:
    public static void doOutput(String[] args, double[][] vector)
    and it should work.

    You can get the size of the passed array with vector.length .
    By the way, in opposition to C++, each element of the array can have a different size. So vector[0].size and vector[1].size can be different!
    That's much better than hardcoding the size of the second index to 40, isn't it?

    Originally posted by aeo3
    Hi all,
    I am trying to pass a two dimensional in java but there a problem in this function
    Code:
        public static void doOutput(String args[], double vector[][40])
    Please what is the problem in this line

    Comment

    • aeo3
      New Member
      • Jul 2007
      • 29

      #3
      That's right. It works now. Thanks

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by chaarmann
        As far as I know, you cannot pass size of dimensions!
        And it's better to use different syntax, not C++ syntax.

        So just write
        Code:
        public static void doOutput(String[] args, double[][] vector)
        and it should work.

        You can get the size of the passed array with vector.length .
        By the way, in opposition to C++, each element of the array can have a different size. So vector[0].size and vector[1].size can be different!
        That's much better than hardcoding the size of the second index to 40, isn't it?
        Hopefully, chaarmann, you will check your PM and respond to me ....

        Comment

        Working...