• Post Reply Bookmark Topic Watch Topic
  • New Topic

The length of each cell of 2D array  RSS feed

 
johnsoan smith
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,

When i create a 2D array like

and is one cell of this 2D array. Can anyone explain me why is equal to 6 which is the number of columns
 
Carey Brown
Bartender
Posts: 3009
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a[1].length is 6
a[1].length-1 is 5
Also, the Java convention is to put the square brackets following the type, like this:
byte[][] a = new byte[3][6];
 
Liutauras Vilda
Marshal
Posts: 4657
320
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
johnsoan smith wrote:Can anyone explain me why

a[1].lenght-1; or a[2].lenght-1;
is equal to 6 which is the number of columns
Not sure I understand your question well, but that is not true. I believe it is equal to 5.

Try to think about this array like this:

That is the same as:
A.length refers to what is in between {...}, A[i].length refers to what is in between {{...}}.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!