This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to find the length of the array  RSS feed

 
Ranch Hand
Posts: 57
  • 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 ]
 
Ranch Hand
Posts: 980
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does a[i].length denotes the no of columns?
 
Ranch Hand
Posts: 1609
  • 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.
 
Ranch Hand
Posts: 579
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI akhil and agrah,thank u for ur clear explanation
 
Sheriff
Posts: 12196
199
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!