What does a method with (int[] []) mean?











up vote
2
down vote

favorite












We are given some code snippets to look at and figure out what the code does/will do.



I understand methods and methods with arrays but I have never seen methodName(int m) with two



What does this mean? an array within an array?










share|improve this question




























    up vote
    2
    down vote

    favorite












    We are given some code snippets to look at and figure out what the code does/will do.



    I understand methods and methods with arrays but I have never seen methodName(int m) with two



    What does this mean? an array within an array?










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      We are given some code snippets to look at and figure out what the code does/will do.



      I understand methods and methods with arrays but I have never seen methodName(int m) with two



      What does this mean? an array within an array?










      share|improve this question















      We are given some code snippets to look at and figure out what the code does/will do.



      I understand methods and methods with arrays but I have never seen methodName(int m) with two



      What does this mean? an array within an array?







      java






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 17:31









      Sotirios Delimanolis

      206k39468559




      206k39468559










      asked Jun 17 '15 at 1:33









      James

      3516




      3516
























          5 Answers
          5






          active

          oldest

          votes

















          up vote
          10
          down vote



          accepted










          int in the method signature refers to a double array of integers. You can think of a double integer array as being a matrix of int values.



          Taking your example 2D array:



          int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};


          This array has the following properties:



          System.out.println(in.length);     // prints 3 (number of arrays inside 'in')
          System.out.println(in[0].length); // prints 3 (number of ints in first array)
          System.out.println(in[1].length); // also prints 3 (number of ints in second array)


          Here is a visual to show you how accessing this array works:



          int a = 1;
          int b = 0;


          Then in[a][b] == in[1][0] == 3:



           2 0 2
          {3 1 2} <-- a = 1 (second subarray)
          1 8 4

          {3 1 2}
          ^-- b = 0 (first element in that subarray)


          The first index a chooses the subarray, and the index b chooses the element inside the subarray.






          share|improve this answer























          • so if the array that the method is using is 'int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};' what would say the length be? 3, 3, 3? or 9?
            – James
            Jun 17 '15 at 1:36










          • @James "what would say the length be? 3, 3, 3? or 9?" - 3 {{3}, {3}, {3}}, in.length is 3, in[0].length is 3, in[1].length is 3, in[2].length is 3
            – MadProgrammer
            Jun 17 '15 at 1:38






          • 1




            @TimBiegeleisen Nope, my testing shows int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}}; in.length as 3, as the first level contains 3 elements...
            – MadProgrammer
            Jun 17 '15 at 1:46










          • @MadProgrammer I stand corrected. I didn't test every use case.
            – Tim Biegeleisen
            Jun 17 '15 at 1:47










          • @TimBiegeleisen Is cool, freaked me out for a minute :P
            – MadProgrammer
            Jun 17 '15 at 1:47


















          up vote
          2
          down vote













          It represents multi dimensional arrays (AKA arrays or arrays) of given data type.
          Think hierarchical to understand it the best way.
          If you have int[3][2], it means,
          It holds value for each of the following index.



          int[0][0]
          int[0][1]
          int[1][0]
          int[1][1]
          int[2][0]
          int[2][1]


          Hope it will help. I struggled a lot to understand it when i was a beginner.
          Possible assign is



          int[3][2] iValue = {{00,01}, {10,11}, {20, 21}}


          Thanks for the correction.






          share|improve this answer



















          • 2




            Java indices are 0-indexed, so the possible indices are: {[0][0], [0][1], [1][0], ..., [2][1]}.
            – Obicere
            Jun 17 '15 at 1:48










          • Thanks for the connection Obicere.
            – VD007
            Jun 17 '15 at 1:52


















          up vote
          1
          down vote













          methodName(int ) is an array of arrays. In response to all the comments, I tested it in eclipse and the length is 3.






          share|improve this answer




























            up vote
            0
            down vote













            In many programming languages (including Java), it is possible to create (and use) an array of arrays. In Java (specifically), all arrays are Object instances. Consider



            Object intArray1 = new int[10];
            Object intArray2 = new int[10];
            Object intArray3 = new int[10];


            Then you might have



            Object arrs = { intArray1, intArray2, intArray3 };


            or even



            Object arrs = new Object { intArray1, intArray2, intArray3 };


            JLS-15.10.1 Run-Time Evaluation of Array Creation Expressions says (in part)




            Otherwise, if n DimExpr expressions appear, then array creation effectively executes a set of nested loops of depth n-1 to create the implied arrays of arrays.



            A multidimensional array need not have arrays of the same length at each level.




            Finally, there is Arrays.deepToString(Object) the Javadoc says (in part)




            Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.







            share|improve this answer




























              up vote
              0
              down vote













              In Java, "int [ ][ ]" stands for a 2-dimensional integer array. To make it easy to understand, simply we can compare 2-d integer array with a simple 1-d integer array;



              1) Down below, a 1-d int array is initialized;



              int arr1d = { 1,2,3 };


              2) And on this one, a 2-d int array is initialized;



              int arr2d = { {1,2,3}, {4,5,6} };


              It is important to understand the structure of 2d arrays. If you print the length of the arr2d , you will get 2 the rows of the array which is 2.



              System.out.println(arr2d.length);


              You will get the length of the outer array, which is actually row count of the array.



              To get the inner array length, which is actually the column count;



              System.out.println(arr2d[0].length);


              Notice that we take the first row, and get the length of the inner array and print the column number.



              To get familiar with the usage of the 2d array in a method, you can check this out;



              private static void printIntegerArray(int intArray) {
              for(int i = 0; i < intArray.length; i++ ) {
              for(int j = 0; j < intArray[i].length; j++ ) {
              System.out.printf("%3d ", intArray[i][j]);
              }
              System.out.println();
              }
              }


              In this static method, int intArray is the only parameter which is obviously a 2 dimensional int array. There are two nested for loops to print the array as a matrix. The outer loop is traversing the rows and the inner loop is traversing on the inner loop.



              Here is the complete example for the 2D Method usage;



              public class Test2DArray {



              public static void main(String args) {
              //Init 2d integer list
              int simpleArray = { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15} };

              //Length of outer array which is actually Row Count;
              System.out.println("Rows : " + simpleArray.length);

              //Length of inner array which is actually Column Count;
              //Notice that we take the first Row to get the Column length
              System.out.println("Columns: " + simpleArray[0].length);

              //Call the printIntegerList method with int parameter
              printIntegerArray(simpleArray);
              }

              private static void printIntegerArray(int intArray) {
              for(int i = 0; i < intArray.length; i++ ) {
              for(int j = 0; j < intArray[i].length; j++ ) {
              System.out.printf("%3d ", intArray[i][j]);
              }
              System.out.println();
              }
              }


              }



              And the output to the console is as below;



              Rows   : 3
              Columns: 5
              1 2 3 4 5
              6 7 8 9 10
              11 12 13 14 15





              share|improve this answer





















                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30880910%2fwhat-does-a-method-with-int-mean%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                10
                down vote



                accepted










                int in the method signature refers to a double array of integers. You can think of a double integer array as being a matrix of int values.



                Taking your example 2D array:



                int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};


                This array has the following properties:



                System.out.println(in.length);     // prints 3 (number of arrays inside 'in')
                System.out.println(in[0].length); // prints 3 (number of ints in first array)
                System.out.println(in[1].length); // also prints 3 (number of ints in second array)


                Here is a visual to show you how accessing this array works:



                int a = 1;
                int b = 0;


                Then in[a][b] == in[1][0] == 3:



                 2 0 2
                {3 1 2} <-- a = 1 (second subarray)
                1 8 4

                {3 1 2}
                ^-- b = 0 (first element in that subarray)


                The first index a chooses the subarray, and the index b chooses the element inside the subarray.






                share|improve this answer























                • so if the array that the method is using is 'int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};' what would say the length be? 3, 3, 3? or 9?
                  – James
                  Jun 17 '15 at 1:36










                • @James "what would say the length be? 3, 3, 3? or 9?" - 3 {{3}, {3}, {3}}, in.length is 3, in[0].length is 3, in[1].length is 3, in[2].length is 3
                  – MadProgrammer
                  Jun 17 '15 at 1:38






                • 1




                  @TimBiegeleisen Nope, my testing shows int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}}; in.length as 3, as the first level contains 3 elements...
                  – MadProgrammer
                  Jun 17 '15 at 1:46










                • @MadProgrammer I stand corrected. I didn't test every use case.
                  – Tim Biegeleisen
                  Jun 17 '15 at 1:47










                • @TimBiegeleisen Is cool, freaked me out for a minute :P
                  – MadProgrammer
                  Jun 17 '15 at 1:47















                up vote
                10
                down vote



                accepted










                int in the method signature refers to a double array of integers. You can think of a double integer array as being a matrix of int values.



                Taking your example 2D array:



                int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};


                This array has the following properties:



                System.out.println(in.length);     // prints 3 (number of arrays inside 'in')
                System.out.println(in[0].length); // prints 3 (number of ints in first array)
                System.out.println(in[1].length); // also prints 3 (number of ints in second array)


                Here is a visual to show you how accessing this array works:



                int a = 1;
                int b = 0;


                Then in[a][b] == in[1][0] == 3:



                 2 0 2
                {3 1 2} <-- a = 1 (second subarray)
                1 8 4

                {3 1 2}
                ^-- b = 0 (first element in that subarray)


                The first index a chooses the subarray, and the index b chooses the element inside the subarray.






                share|improve this answer























                • so if the array that the method is using is 'int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};' what would say the length be? 3, 3, 3? or 9?
                  – James
                  Jun 17 '15 at 1:36










                • @James "what would say the length be? 3, 3, 3? or 9?" - 3 {{3}, {3}, {3}}, in.length is 3, in[0].length is 3, in[1].length is 3, in[2].length is 3
                  – MadProgrammer
                  Jun 17 '15 at 1:38






                • 1




                  @TimBiegeleisen Nope, my testing shows int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}}; in.length as 3, as the first level contains 3 elements...
                  – MadProgrammer
                  Jun 17 '15 at 1:46










                • @MadProgrammer I stand corrected. I didn't test every use case.
                  – Tim Biegeleisen
                  Jun 17 '15 at 1:47










                • @TimBiegeleisen Is cool, freaked me out for a minute :P
                  – MadProgrammer
                  Jun 17 '15 at 1:47













                up vote
                10
                down vote



                accepted







                up vote
                10
                down vote



                accepted






                int in the method signature refers to a double array of integers. You can think of a double integer array as being a matrix of int values.



                Taking your example 2D array:



                int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};


                This array has the following properties:



                System.out.println(in.length);     // prints 3 (number of arrays inside 'in')
                System.out.println(in[0].length); // prints 3 (number of ints in first array)
                System.out.println(in[1].length); // also prints 3 (number of ints in second array)


                Here is a visual to show you how accessing this array works:



                int a = 1;
                int b = 0;


                Then in[a][b] == in[1][0] == 3:



                 2 0 2
                {3 1 2} <-- a = 1 (second subarray)
                1 8 4

                {3 1 2}
                ^-- b = 0 (first element in that subarray)


                The first index a chooses the subarray, and the index b chooses the element inside the subarray.






                share|improve this answer














                int in the method signature refers to a double array of integers. You can think of a double integer array as being a matrix of int values.



                Taking your example 2D array:



                int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};


                This array has the following properties:



                System.out.println(in.length);     // prints 3 (number of arrays inside 'in')
                System.out.println(in[0].length); // prints 3 (number of ints in first array)
                System.out.println(in[1].length); // also prints 3 (number of ints in second array)


                Here is a visual to show you how accessing this array works:



                int a = 1;
                int b = 0;


                Then in[a][b] == in[1][0] == 3:



                 2 0 2
                {3 1 2} <-- a = 1 (second subarray)
                1 8 4

                {3 1 2}
                ^-- b = 0 (first element in that subarray)


                The first index a chooses the subarray, and the index b chooses the element inside the subarray.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 17 '15 at 2:10

























                answered Jun 17 '15 at 1:35









                Tim Biegeleisen

                212k1384132




                212k1384132












                • so if the array that the method is using is 'int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};' what would say the length be? 3, 3, 3? or 9?
                  – James
                  Jun 17 '15 at 1:36










                • @James "what would say the length be? 3, 3, 3? or 9?" - 3 {{3}, {3}, {3}}, in.length is 3, in[0].length is 3, in[1].length is 3, in[2].length is 3
                  – MadProgrammer
                  Jun 17 '15 at 1:38






                • 1




                  @TimBiegeleisen Nope, my testing shows int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}}; in.length as 3, as the first level contains 3 elements...
                  – MadProgrammer
                  Jun 17 '15 at 1:46










                • @MadProgrammer I stand corrected. I didn't test every use case.
                  – Tim Biegeleisen
                  Jun 17 '15 at 1:47










                • @TimBiegeleisen Is cool, freaked me out for a minute :P
                  – MadProgrammer
                  Jun 17 '15 at 1:47


















                • so if the array that the method is using is 'int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};' what would say the length be? 3, 3, 3? or 9?
                  – James
                  Jun 17 '15 at 1:36










                • @James "what would say the length be? 3, 3, 3? or 9?" - 3 {{3}, {3}, {3}}, in.length is 3, in[0].length is 3, in[1].length is 3, in[2].length is 3
                  – MadProgrammer
                  Jun 17 '15 at 1:38






                • 1




                  @TimBiegeleisen Nope, my testing shows int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}}; in.length as 3, as the first level contains 3 elements...
                  – MadProgrammer
                  Jun 17 '15 at 1:46










                • @MadProgrammer I stand corrected. I didn't test every use case.
                  – Tim Biegeleisen
                  Jun 17 '15 at 1:47










                • @TimBiegeleisen Is cool, freaked me out for a minute :P
                  – MadProgrammer
                  Jun 17 '15 at 1:47
















                so if the array that the method is using is 'int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};' what would say the length be? 3, 3, 3? or 9?
                – James
                Jun 17 '15 at 1:36




                so if the array that the method is using is 'int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}};' what would say the length be? 3, 3, 3? or 9?
                – James
                Jun 17 '15 at 1:36












                @James "what would say the length be? 3, 3, 3? or 9?" - 3 {{3}, {3}, {3}}, in.length is 3, in[0].length is 3, in[1].length is 3, in[2].length is 3
                – MadProgrammer
                Jun 17 '15 at 1:38




                @James "what would say the length be? 3, 3, 3? or 9?" - 3 {{3}, {3}, {3}}, in.length is 3, in[0].length is 3, in[1].length is 3, in[2].length is 3
                – MadProgrammer
                Jun 17 '15 at 1:38




                1




                1




                @TimBiegeleisen Nope, my testing shows int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}}; in.length as 3, as the first level contains 3 elements...
                – MadProgrammer
                Jun 17 '15 at 1:46




                @TimBiegeleisen Nope, my testing shows int in = {{2, 0, 2}, {3, 1, 2}, {1, 8, 4}}; in.length as 3, as the first level contains 3 elements...
                – MadProgrammer
                Jun 17 '15 at 1:46












                @MadProgrammer I stand corrected. I didn't test every use case.
                – Tim Biegeleisen
                Jun 17 '15 at 1:47




                @MadProgrammer I stand corrected. I didn't test every use case.
                – Tim Biegeleisen
                Jun 17 '15 at 1:47












                @TimBiegeleisen Is cool, freaked me out for a minute :P
                – MadProgrammer
                Jun 17 '15 at 1:47




                @TimBiegeleisen Is cool, freaked me out for a minute :P
                – MadProgrammer
                Jun 17 '15 at 1:47












                up vote
                2
                down vote













                It represents multi dimensional arrays (AKA arrays or arrays) of given data type.
                Think hierarchical to understand it the best way.
                If you have int[3][2], it means,
                It holds value for each of the following index.



                int[0][0]
                int[0][1]
                int[1][0]
                int[1][1]
                int[2][0]
                int[2][1]


                Hope it will help. I struggled a lot to understand it when i was a beginner.
                Possible assign is



                int[3][2] iValue = {{00,01}, {10,11}, {20, 21}}


                Thanks for the correction.






                share|improve this answer



















                • 2




                  Java indices are 0-indexed, so the possible indices are: {[0][0], [0][1], [1][0], ..., [2][1]}.
                  – Obicere
                  Jun 17 '15 at 1:48










                • Thanks for the connection Obicere.
                  – VD007
                  Jun 17 '15 at 1:52















                up vote
                2
                down vote













                It represents multi dimensional arrays (AKA arrays or arrays) of given data type.
                Think hierarchical to understand it the best way.
                If you have int[3][2], it means,
                It holds value for each of the following index.



                int[0][0]
                int[0][1]
                int[1][0]
                int[1][1]
                int[2][0]
                int[2][1]


                Hope it will help. I struggled a lot to understand it when i was a beginner.
                Possible assign is



                int[3][2] iValue = {{00,01}, {10,11}, {20, 21}}


                Thanks for the correction.






                share|improve this answer



















                • 2




                  Java indices are 0-indexed, so the possible indices are: {[0][0], [0][1], [1][0], ..., [2][1]}.
                  – Obicere
                  Jun 17 '15 at 1:48










                • Thanks for the connection Obicere.
                  – VD007
                  Jun 17 '15 at 1:52













                up vote
                2
                down vote










                up vote
                2
                down vote









                It represents multi dimensional arrays (AKA arrays or arrays) of given data type.
                Think hierarchical to understand it the best way.
                If you have int[3][2], it means,
                It holds value for each of the following index.



                int[0][0]
                int[0][1]
                int[1][0]
                int[1][1]
                int[2][0]
                int[2][1]


                Hope it will help. I struggled a lot to understand it when i was a beginner.
                Possible assign is



                int[3][2] iValue = {{00,01}, {10,11}, {20, 21}}


                Thanks for the correction.






                share|improve this answer














                It represents multi dimensional arrays (AKA arrays or arrays) of given data type.
                Think hierarchical to understand it the best way.
                If you have int[3][2], it means,
                It holds value for each of the following index.



                int[0][0]
                int[0][1]
                int[1][0]
                int[1][1]
                int[2][0]
                int[2][1]


                Hope it will help. I struggled a lot to understand it when i was a beginner.
                Possible assign is



                int[3][2] iValue = {{00,01}, {10,11}, {20, 21}}


                Thanks for the correction.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 24 '15 at 18:06









                Brian Tompsett - 汤莱恩

                4,153133699




                4,153133699










                answered Jun 17 '15 at 1:39









                VD007

                199113




                199113








                • 2




                  Java indices are 0-indexed, so the possible indices are: {[0][0], [0][1], [1][0], ..., [2][1]}.
                  – Obicere
                  Jun 17 '15 at 1:48










                • Thanks for the connection Obicere.
                  – VD007
                  Jun 17 '15 at 1:52














                • 2




                  Java indices are 0-indexed, so the possible indices are: {[0][0], [0][1], [1][0], ..., [2][1]}.
                  – Obicere
                  Jun 17 '15 at 1:48










                • Thanks for the connection Obicere.
                  – VD007
                  Jun 17 '15 at 1:52








                2




                2




                Java indices are 0-indexed, so the possible indices are: {[0][0], [0][1], [1][0], ..., [2][1]}.
                – Obicere
                Jun 17 '15 at 1:48




                Java indices are 0-indexed, so the possible indices are: {[0][0], [0][1], [1][0], ..., [2][1]}.
                – Obicere
                Jun 17 '15 at 1:48












                Thanks for the connection Obicere.
                – VD007
                Jun 17 '15 at 1:52




                Thanks for the connection Obicere.
                – VD007
                Jun 17 '15 at 1:52










                up vote
                1
                down vote













                methodName(int ) is an array of arrays. In response to all the comments, I tested it in eclipse and the length is 3.






                share|improve this answer

























                  up vote
                  1
                  down vote













                  methodName(int ) is an array of arrays. In response to all the comments, I tested it in eclipse and the length is 3.






                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    methodName(int ) is an array of arrays. In response to all the comments, I tested it in eclipse and the length is 3.






                    share|improve this answer












                    methodName(int ) is an array of arrays. In response to all the comments, I tested it in eclipse and the length is 3.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 17 '15 at 1:42







                    user4920910





























                        up vote
                        0
                        down vote













                        In many programming languages (including Java), it is possible to create (and use) an array of arrays. In Java (specifically), all arrays are Object instances. Consider



                        Object intArray1 = new int[10];
                        Object intArray2 = new int[10];
                        Object intArray3 = new int[10];


                        Then you might have



                        Object arrs = { intArray1, intArray2, intArray3 };


                        or even



                        Object arrs = new Object { intArray1, intArray2, intArray3 };


                        JLS-15.10.1 Run-Time Evaluation of Array Creation Expressions says (in part)




                        Otherwise, if n DimExpr expressions appear, then array creation effectively executes a set of nested loops of depth n-1 to create the implied arrays of arrays.



                        A multidimensional array need not have arrays of the same length at each level.




                        Finally, there is Arrays.deepToString(Object) the Javadoc says (in part)




                        Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.







                        share|improve this answer

























                          up vote
                          0
                          down vote













                          In many programming languages (including Java), it is possible to create (and use) an array of arrays. In Java (specifically), all arrays are Object instances. Consider



                          Object intArray1 = new int[10];
                          Object intArray2 = new int[10];
                          Object intArray3 = new int[10];


                          Then you might have



                          Object arrs = { intArray1, intArray2, intArray3 };


                          or even



                          Object arrs = new Object { intArray1, intArray2, intArray3 };


                          JLS-15.10.1 Run-Time Evaluation of Array Creation Expressions says (in part)




                          Otherwise, if n DimExpr expressions appear, then array creation effectively executes a set of nested loops of depth n-1 to create the implied arrays of arrays.



                          A multidimensional array need not have arrays of the same length at each level.




                          Finally, there is Arrays.deepToString(Object) the Javadoc says (in part)




                          Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.







                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            In many programming languages (including Java), it is possible to create (and use) an array of arrays. In Java (specifically), all arrays are Object instances. Consider



                            Object intArray1 = new int[10];
                            Object intArray2 = new int[10];
                            Object intArray3 = new int[10];


                            Then you might have



                            Object arrs = { intArray1, intArray2, intArray3 };


                            or even



                            Object arrs = new Object { intArray1, intArray2, intArray3 };


                            JLS-15.10.1 Run-Time Evaluation of Array Creation Expressions says (in part)




                            Otherwise, if n DimExpr expressions appear, then array creation effectively executes a set of nested loops of depth n-1 to create the implied arrays of arrays.



                            A multidimensional array need not have arrays of the same length at each level.




                            Finally, there is Arrays.deepToString(Object) the Javadoc says (in part)




                            Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.







                            share|improve this answer












                            In many programming languages (including Java), it is possible to create (and use) an array of arrays. In Java (specifically), all arrays are Object instances. Consider



                            Object intArray1 = new int[10];
                            Object intArray2 = new int[10];
                            Object intArray3 = new int[10];


                            Then you might have



                            Object arrs = { intArray1, intArray2, intArray3 };


                            or even



                            Object arrs = new Object { intArray1, intArray2, intArray3 };


                            JLS-15.10.1 Run-Time Evaluation of Array Creation Expressions says (in part)




                            Otherwise, if n DimExpr expressions appear, then array creation effectively executes a set of nested loops of depth n-1 to create the implied arrays of arrays.



                            A multidimensional array need not have arrays of the same length at each level.




                            Finally, there is Arrays.deepToString(Object) the Javadoc says (in part)




                            Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.








                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jun 17 '15 at 1:49









                            Elliott Frisch

                            151k1389175




                            151k1389175






















                                up vote
                                0
                                down vote













                                In Java, "int [ ][ ]" stands for a 2-dimensional integer array. To make it easy to understand, simply we can compare 2-d integer array with a simple 1-d integer array;



                                1) Down below, a 1-d int array is initialized;



                                int arr1d = { 1,2,3 };


                                2) And on this one, a 2-d int array is initialized;



                                int arr2d = { {1,2,3}, {4,5,6} };


                                It is important to understand the structure of 2d arrays. If you print the length of the arr2d , you will get 2 the rows of the array which is 2.



                                System.out.println(arr2d.length);


                                You will get the length of the outer array, which is actually row count of the array.



                                To get the inner array length, which is actually the column count;



                                System.out.println(arr2d[0].length);


                                Notice that we take the first row, and get the length of the inner array and print the column number.



                                To get familiar with the usage of the 2d array in a method, you can check this out;



                                private static void printIntegerArray(int intArray) {
                                for(int i = 0; i < intArray.length; i++ ) {
                                for(int j = 0; j < intArray[i].length; j++ ) {
                                System.out.printf("%3d ", intArray[i][j]);
                                }
                                System.out.println();
                                }
                                }


                                In this static method, int intArray is the only parameter which is obviously a 2 dimensional int array. There are two nested for loops to print the array as a matrix. The outer loop is traversing the rows and the inner loop is traversing on the inner loop.



                                Here is the complete example for the 2D Method usage;



                                public class Test2DArray {



                                public static void main(String args) {
                                //Init 2d integer list
                                int simpleArray = { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15} };

                                //Length of outer array which is actually Row Count;
                                System.out.println("Rows : " + simpleArray.length);

                                //Length of inner array which is actually Column Count;
                                //Notice that we take the first Row to get the Column length
                                System.out.println("Columns: " + simpleArray[0].length);

                                //Call the printIntegerList method with int parameter
                                printIntegerArray(simpleArray);
                                }

                                private static void printIntegerArray(int intArray) {
                                for(int i = 0; i < intArray.length; i++ ) {
                                for(int j = 0; j < intArray[i].length; j++ ) {
                                System.out.printf("%3d ", intArray[i][j]);
                                }
                                System.out.println();
                                }
                                }


                                }



                                And the output to the console is as below;



                                Rows   : 3
                                Columns: 5
                                1 2 3 4 5
                                6 7 8 9 10
                                11 12 13 14 15





                                share|improve this answer

























                                  up vote
                                  0
                                  down vote













                                  In Java, "int [ ][ ]" stands for a 2-dimensional integer array. To make it easy to understand, simply we can compare 2-d integer array with a simple 1-d integer array;



                                  1) Down below, a 1-d int array is initialized;



                                  int arr1d = { 1,2,3 };


                                  2) And on this one, a 2-d int array is initialized;



                                  int arr2d = { {1,2,3}, {4,5,6} };


                                  It is important to understand the structure of 2d arrays. If you print the length of the arr2d , you will get 2 the rows of the array which is 2.



                                  System.out.println(arr2d.length);


                                  You will get the length of the outer array, which is actually row count of the array.



                                  To get the inner array length, which is actually the column count;



                                  System.out.println(arr2d[0].length);


                                  Notice that we take the first row, and get the length of the inner array and print the column number.



                                  To get familiar with the usage of the 2d array in a method, you can check this out;



                                  private static void printIntegerArray(int intArray) {
                                  for(int i = 0; i < intArray.length; i++ ) {
                                  for(int j = 0; j < intArray[i].length; j++ ) {
                                  System.out.printf("%3d ", intArray[i][j]);
                                  }
                                  System.out.println();
                                  }
                                  }


                                  In this static method, int intArray is the only parameter which is obviously a 2 dimensional int array. There are two nested for loops to print the array as a matrix. The outer loop is traversing the rows and the inner loop is traversing on the inner loop.



                                  Here is the complete example for the 2D Method usage;



                                  public class Test2DArray {



                                  public static void main(String args) {
                                  //Init 2d integer list
                                  int simpleArray = { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15} };

                                  //Length of outer array which is actually Row Count;
                                  System.out.println("Rows : " + simpleArray.length);

                                  //Length of inner array which is actually Column Count;
                                  //Notice that we take the first Row to get the Column length
                                  System.out.println("Columns: " + simpleArray[0].length);

                                  //Call the printIntegerList method with int parameter
                                  printIntegerArray(simpleArray);
                                  }

                                  private static void printIntegerArray(int intArray) {
                                  for(int i = 0; i < intArray.length; i++ ) {
                                  for(int j = 0; j < intArray[i].length; j++ ) {
                                  System.out.printf("%3d ", intArray[i][j]);
                                  }
                                  System.out.println();
                                  }
                                  }


                                  }



                                  And the output to the console is as below;



                                  Rows   : 3
                                  Columns: 5
                                  1 2 3 4 5
                                  6 7 8 9 10
                                  11 12 13 14 15





                                  share|improve this answer























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    In Java, "int [ ][ ]" stands for a 2-dimensional integer array. To make it easy to understand, simply we can compare 2-d integer array with a simple 1-d integer array;



                                    1) Down below, a 1-d int array is initialized;



                                    int arr1d = { 1,2,3 };


                                    2) And on this one, a 2-d int array is initialized;



                                    int arr2d = { {1,2,3}, {4,5,6} };


                                    It is important to understand the structure of 2d arrays. If you print the length of the arr2d , you will get 2 the rows of the array which is 2.



                                    System.out.println(arr2d.length);


                                    You will get the length of the outer array, which is actually row count of the array.



                                    To get the inner array length, which is actually the column count;



                                    System.out.println(arr2d[0].length);


                                    Notice that we take the first row, and get the length of the inner array and print the column number.



                                    To get familiar with the usage of the 2d array in a method, you can check this out;



                                    private static void printIntegerArray(int intArray) {
                                    for(int i = 0; i < intArray.length; i++ ) {
                                    for(int j = 0; j < intArray[i].length; j++ ) {
                                    System.out.printf("%3d ", intArray[i][j]);
                                    }
                                    System.out.println();
                                    }
                                    }


                                    In this static method, int intArray is the only parameter which is obviously a 2 dimensional int array. There are two nested for loops to print the array as a matrix. The outer loop is traversing the rows and the inner loop is traversing on the inner loop.



                                    Here is the complete example for the 2D Method usage;



                                    public class Test2DArray {



                                    public static void main(String args) {
                                    //Init 2d integer list
                                    int simpleArray = { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15} };

                                    //Length of outer array which is actually Row Count;
                                    System.out.println("Rows : " + simpleArray.length);

                                    //Length of inner array which is actually Column Count;
                                    //Notice that we take the first Row to get the Column length
                                    System.out.println("Columns: " + simpleArray[0].length);

                                    //Call the printIntegerList method with int parameter
                                    printIntegerArray(simpleArray);
                                    }

                                    private static void printIntegerArray(int intArray) {
                                    for(int i = 0; i < intArray.length; i++ ) {
                                    for(int j = 0; j < intArray[i].length; j++ ) {
                                    System.out.printf("%3d ", intArray[i][j]);
                                    }
                                    System.out.println();
                                    }
                                    }


                                    }



                                    And the output to the console is as below;



                                    Rows   : 3
                                    Columns: 5
                                    1 2 3 4 5
                                    6 7 8 9 10
                                    11 12 13 14 15





                                    share|improve this answer












                                    In Java, "int [ ][ ]" stands for a 2-dimensional integer array. To make it easy to understand, simply we can compare 2-d integer array with a simple 1-d integer array;



                                    1) Down below, a 1-d int array is initialized;



                                    int arr1d = { 1,2,3 };


                                    2) And on this one, a 2-d int array is initialized;



                                    int arr2d = { {1,2,3}, {4,5,6} };


                                    It is important to understand the structure of 2d arrays. If you print the length of the arr2d , you will get 2 the rows of the array which is 2.



                                    System.out.println(arr2d.length);


                                    You will get the length of the outer array, which is actually row count of the array.



                                    To get the inner array length, which is actually the column count;



                                    System.out.println(arr2d[0].length);


                                    Notice that we take the first row, and get the length of the inner array and print the column number.



                                    To get familiar with the usage of the 2d array in a method, you can check this out;



                                    private static void printIntegerArray(int intArray) {
                                    for(int i = 0; i < intArray.length; i++ ) {
                                    for(int j = 0; j < intArray[i].length; j++ ) {
                                    System.out.printf("%3d ", intArray[i][j]);
                                    }
                                    System.out.println();
                                    }
                                    }


                                    In this static method, int intArray is the only parameter which is obviously a 2 dimensional int array. There are two nested for loops to print the array as a matrix. The outer loop is traversing the rows and the inner loop is traversing on the inner loop.



                                    Here is the complete example for the 2D Method usage;



                                    public class Test2DArray {



                                    public static void main(String args) {
                                    //Init 2d integer list
                                    int simpleArray = { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15} };

                                    //Length of outer array which is actually Row Count;
                                    System.out.println("Rows : " + simpleArray.length);

                                    //Length of inner array which is actually Column Count;
                                    //Notice that we take the first Row to get the Column length
                                    System.out.println("Columns: " + simpleArray[0].length);

                                    //Call the printIntegerList method with int parameter
                                    printIntegerArray(simpleArray);
                                    }

                                    private static void printIntegerArray(int intArray) {
                                    for(int i = 0; i < intArray.length; i++ ) {
                                    for(int j = 0; j < intArray[i].length; j++ ) {
                                    System.out.printf("%3d ", intArray[i][j]);
                                    }
                                    System.out.println();
                                    }
                                    }


                                    }



                                    And the output to the console is as below;



                                    Rows   : 3
                                    Columns: 5
                                    1 2 3 4 5
                                    6 7 8 9 10
                                    11 12 13 14 15






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jun 17 '15 at 8:45









                                    Levent Divilioglu

                                    6,13533282




                                    6,13533282






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30880910%2fwhat-does-a-method-with-int-mean%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Costa Masnaga

                                        Fotorealismo

                                        Sidney Franklin