File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find the length of the array

 
Jenny raj
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In the above program how does the value of a[i].length is 3?
[ October 03, 2005: Message edited by: Barry Gaunt ]
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

this is a 4 X 3 matrix..

which means

a.length gives you 4 ...the no of rows..

[0][0] [0][1] [0][2] <-Now when a[i]..that is individual rows
[1][0] [1][1] [1][2] are scanned...you have columns to store
[2][0] [2][1] [2][2] values.So length is 3
[3][0] [3][1] [3][2]


Hope you got it..
 
Jenny raj
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't understand

are u trying to say that a[i].length gives the length of the column?
 
Jenny raj
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does a[i].length denotes the no of columns?
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jenny!
What is length of an array actually mean, number of elements right???

If "a" is 1-D (One dimensional) array then a.lenth would mean number of elements in the 1-D array.
If a is 2-D array then a[i].length means number of elements, you can have at a[i].
if "a" is 3-D array then a[i][j] means number of elements you can have at a[i][j].

Very very generally speaking, there are no terms like rows or columns... we give the name for our convenience. Hope this helps.
 
agrah upadhyay
Ranch Hand
Posts: 579
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int a[][]=new int[4][3];

Here "int a[][]" OR ("int[][] a") denotes that a is a reference of a "2D array"(due to [][]).And elements (not references )stored actually are of "int" data type.Always visualise array in this very manner.
Now int[][] a=new int[4][3] declares that a is a reference of such a object which stores 4 references of 1-D array and each of which reference such a object having 3 element of int data type.Just see it pictorically.....where references are denoted by dot(.) aand object by box.Hope it clears!
 
Jenny raj
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI akhil and agrah,thank u for ur neat explanation
 
Jenny raj
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI akhil and agrah,thank u for ur clear explanation
 
Junilu Lacar
Bartender
Pie
Posts: 6548
22
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java arrays are actually 1-dimensional, just like C (see http://www.eskimo.com/~scs/cclass/int/sx9.html ). You can, however, nest arrays within arrays and this is how you can simulate "multiple" dimensions.

See also: http://java.sun.com/docs/books/tutorial/java/data/multiarrays.html
[ October 05, 2005: Message edited by: Junilu Lacar ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic