• Post Reply Bookmark Topic Watch Topic
  • New Topic

array's dimension  RSS feed

 
p sandeep
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

My name is sandeep. Recently,i went through a bit given below.can anyone explain it

What is the maximium number of dimensions an array can accept:

a.266
b.255
c.256
d.250
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the VM used. The Sun's standard JVM can hold a 8-bit size of array. So the answer is 2^8 - 1 = 255.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked in Java Language Specification, which is where you should look for such information.

There is no mention of a maximum number of dimensions for an array, so I guess that, in theory, it is not limited at all. Therefore, all the options you present look wrong.

In practice, an array with more than, say, 3 dimensions is horribly unwieldy. Even if you are allowed a 40-dimension array (let alone 250-dimension), you'd never want to use one. You'd have to declare it like this: -



This is not really a very interesting question. Move on...
[ October 09, 2006: Message edited by: Peter Chase ]
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was so kind to test it in WebSphere running JVM 1.4 and the following compilation error was returned when I tried to declare an ordinary array with more than 255 dimensions:
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is actually metioned somewhere in the JVM specification -- as part of a list of limitations. IMHO, it is pretty well buried in the document.

Basically, there is a limit of 255 "dimensions" of arrays that can be declared.

But I agree with Peter, using that many is horribly unwieldy, and should be avoided.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!