Forums Register Login

multidimensional array to singledimensional array and otherway around

1
+Pie Number of slices to send: Send
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


1
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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[].
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thank you very much for the clarification Stephan.
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 589 times.
Similar Threads
Uni JAVA Exam Monday HELP!!
two dimensional Java arrays
Multi-dim Array
Master Exam Array question
Array Reference Assignments
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:56:35.