This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Java in General and the fly likes Storing 2D into Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Storing 2D into "1D"" Watch "Storing 2D into "1D"" New topic

Storing 2D into "1D"

John Stevens

Joined: Oct 24, 2003
Posts: 5
Just an extension of my last post on Tridiagonal matrix.
I've got for example the following matrix:
1 4 0 0
1 3 5 0
0 3 4 4
0 0 6 6
How do I store only the non-zero numbers in a one dimensional array in this order:
1, 4, 1, 3, 5, 3, 4, 4, 6, 6
Vinod Venkatasubramanian

Joined: Oct 19, 2003
Posts: 13
If efficieny is not an issue, you could try using ArrayList to dynamically grow the array.
Basically, traverse the input array and for every element you want inserted into the destination array, use ArrayList.add.
I agree. Here's the link:
subject: Storing 2D into "1D"
It's not a secret anymore!