• Post Reply Bookmark Topic Watch Topic
  • New Topic

multidimensional array to singledimensional array and otherway around  RSS feed

 
Radjiv Raghoebier
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I tried to make the assignment here under, but i dont understand it.

Here is the code:
-------------------------------------------------------------------------------------------------------------------------------


According to the answer this is the same as:


-------------------------------------------------------------------------------------------

This code got me confused and i like to know the following:

Is it possible to assign a mulit-dimensional array to a single-dimensional array variable?
Why is only the {null} at the simplification is assigned to the variable ejgStr[]?
What is the [0] at the end of the initialization ? and how can i relate it to the variable ejgStr[]?

Can someone help me?

Thanks


 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Radjiv Raghoebier wrote:
Is it possible to assign a mulit-dimensional array to a single-dimensional array variable?

Have you tried it ? What happened ? By the way, the code you posted is not doing that.

Radjiv Raghoebier wrote:
Why is only the {null} at the simplification is assigned to the variable ejgStr[]?

Because that's what the code is designed to do. See below.

Radjiv Raghoebier wrote:
What is the [0] at the end of the initialization ?

That is the syntax for accessing the first element of an array.
The code is creating an array of String arrays and then accessing the first element of this array. It then assigns this value to ejgStr.
It's the equivalent of
 
Radjiv Raghoebier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Stuart. I think i get it now.
So basicly it asigns the first array(out of the three arrays from the two dimensional array) to the variable ejgStr[].
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. Note however that Java does not have multidimensional arrays. N-dimension arrays are rectangular, cuboid, etc... Java only has linear arrays, but can have other arrays as its elements: String[][] is not a two dimensional array, it's an array of arrays.
 
Radjiv Raghoebier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the clarification Stephan.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!