Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dimension in array  RSS feed

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear sir what is the maximum number of Dimension an array can acept in java or any other programing language

Ans a.266 b.255 c.256 d.250

with regard

Arun kumar maalik
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, 1.

You can have arrays in Java, but you can't have multi-dimensional arrays. What appears to be a 2-directional array is not that; it is actually a 1-dimensional array of 1-dimensional arrays.
What appears to be a 3-dimensional array is not that, it is a 1-dimensional array of 1-dimensional arrays of 1-dimenisonal arrays.

That means you can write
and myArray[2] or myJaggedArray[2] then act as ordinary int[] arrays.

The answer to the question you meant to ask and didn't is (if I remember correctly) 255 in Java.

Other languages-don't know.
 
Adam Nace
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
The answer to the question you meant to ask and didn't is (if I remember correctly) 255 in Java.


??

Perhaps you could tell us what the quetstion he meant to ask and didn't is, because I'm not sure what you're trying to answer here. I'm not aware of any size restriction that limits the number of elements in an array to 255, nor can I figure out any reason why you could not have a tree of greater depth than 255 made with arrays. Did I miss something here?

My answer to the original question would be this: You can have as many dimensions in an array as you like, and as many indices in each dimension as you would like, provided your system has the memory available for it.

- Adam
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I actually tried creating an array with a large number of dimensions, my Eclipse compiler produced this message:
Too many array dimensions. Maximum is 255.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this is specified in the JLS (though it should be), but it's in the JVMS: "The number of dimensions in an array is limited to 255 by the size of the dimensions opcode of the multianewarray instruction and by the constraints imposed on the multianewarray, anewarray, and newarray instructions by �4.8.2."
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any other test questions you'd like us to fill in or are you just going to Christmas tree the rest?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!