# Array Length

 Sumanpal Singh · March 8, 2015 Java Programming Tutorial - 34 - Table for Multi Arraysi can't understand the the legnth of array in this example

## Replies

 Sumanpal Singh · March 13, 2015 Thanks Nicholas ........ Nicholas Eason · March 12, 2015 A different example:You have this sweet stair case that doubles as a multidimensional array(pretty sweet, right?):``//COOL STAIRCASE ARRAY:int stairs[][] = {{1},{1 2},{1 2 3},{1 2 3 4},{1 2 3 4 5}};``stairs.length() will return 5, and it's pretty obvious why. Your staircase has 5 steps!Now, since it's a staircase, each of the STEPS are a different length. So stairs[2].length() is not the same as stairs[3].length().KEEP IN MIND: Arrays start with an index of 0You'll see that stairs[2].length() will return 3stairs[3].length will return 4 Dol Lod · March 9, 2015 np Sumanpal Singh · March 9, 2015 Thanks Arjun , Very well explained . Dol Lod · March 8, 2015 In java, length is a built in part of arrays to tell you how long they are. In this case, length is being used to make sure he has valid access to the given elements in his table. He is using row access for each two dimensional array. ex. table1 2 3 45 6 7 89 10 11 12 13 14 15 16When he uses the outer length, he is checking against how many rows he has on the table to make sure he has defined access and  then grabbing the row. Then he prints out each column in the row individually by navigating through the columns one at a time until there are no more columns left to print out, going to the next row.
• 1

## Java / Android Development

130,854 followers

Very popular language used to create desktop applications, website applets, and Android apps.