• Post Reply Bookmark Topic Watch Topic
  • New Topic

array  RSS feed

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all friends!!

Recently someone asked me " if it was possible to have an array which is single dimensional but contains an index which holds multiple values?"

something of the form {1,2,3,4,{6,7},8,9}

i found this absurd but then he was pretty sure.Please help me if it is possible and how? He called it Jet Array.Is there something like this in java?

Thanks for your precious time
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, no, an index into an array holds exactly one object -- but that's not to say that the object can't hold other objects.

For example:

 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each element in an array is a single value -- either a primitive or an object reference. And everything in an array must be the same type.

Technically, all arrays in Java are one-dimensional. What we call a "multi-dimensional array" in Java is really just an array that holds other arrays. So you can certainly have something like...

{ {1}, {2, 3}, {4}, {5, 6, 7, 8}, {9} }

...where the "outer" array holds 5 int arrays (of different lengths). But you can not have...

{ 1, {2, 3}, 4, {5, 6, 7, 8}, 9 }

...where the elements appear to be different types (a mixture of ints and arrays).
[ September 10, 2007: Message edited by: marc weber ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!