• Post Reply Bookmark Topic Watch Topic
  • New Topic

release 1 dimensional array from 2 dimensional array  RSS feed

 
Defa Lukman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a 2x2 matrix and a 2 dimensional array.
Let's say, my matrix is [a b] and array is [[1, 2], [3, 4], [5, 6],[23, 11]]
I need to multiply each 1 dimensional array in above array with the matrix.
For instance,
[1, 2] multiply with [a b]
[3, 4] multiply with [a b]
[5, 6] multiply with [a b]
[23, 11] multiply with [a b]

So, each 1 dimensional array in there will be multiplied with matrix [a b]
(same with matrix multiplication).

I can figure out how to do that multiplication in java. But I confuse how to 'release' each 1 dimensional array from the first array so I can do multiplication.
How to do that in java?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is no such thing as a 2‑D array in Java®. You have an array of arrays. Each element is an array.
System.out.println(Arrays.toString(numbers[0])); // Won't work for a 0‑element array.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a 2×1 matrix (or 1×2), not 2×2.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Speaky Share wrote:I can figure out how to do that multiplication in java. But I confuse how to 'release' each 1 dimensional array from the first array so I can do multiplication.

I'm not quite sure what you mean by 'release'. If you want to keep a copy of the original array (maybe a good idea), then you need to copy it first (have a look at Arrays.deepCopy()). If not, then arrays are mutable, so simply assign the result to the original element.

HIH

Winston
 
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!