Lets say we have an 1d array called array. Now I know array.length gives me how many primitive types or objects are in a 1d array but what does it do for a 2d array with rows with different rows?

{1, 2, 3, 4}
array.length would be 4

but if its like

{1, 2, 3, 4}
{5, 6, 7}
{8, 9, 10, 11, 12}

what does the array.length return? I tried making a 2d array with uneven rows

public static void masin()
   {
    // declare and construct a 2D array
    int[][] uneven = 
        { { 1, 9, 4, 3, 32 },
          { 0, 2},
          { 0, 1, 2, 3, 4 } };

    System.out.println( uneven.length );
 }

but all terminal gave me was 3 no matter how I changed the array.

oops I really am an idiot.

I figured it out after looking at how I made the 2d array, it's an array within an array and a.length returns the rows I've put in.

I really- dfgdfgdfgfdg thanks anyway.

array.length in 2d array returns the number of rows you entred but if you want to get the number of coloum, you must specify at first which row you want to get the length of it
Ex.

int [][]array=  { { 1, 9, 4, 3, 32 },
          { 0, 2},
          { 0, 1, 2, 3, 4 } };
array.length returns 3

but if you want to know the number of coloum

a[no_of_row].length returns 5 if no_of_row=0
returns 3. because arrayname.length in 2d array will return only the row value (ie)
for ex              int a[][]=new int [2][3];
              answer is = 2

Pushparaj ruban
This question was answered a year ago. Do you think the OP is still waiting for someone to confirm it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.