The moose likes Beginning Java and the fly likes single dimension array to multi dimension Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "single dimension array to multi dimension" Watch "single dimension array to multi dimension" New topic

single dimension array to multi dimension

vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
I have the requirement in the project to store the single dimensional array value to multi dimensioinal array.
I ve array of blocks(area)from which I want to split each block(area) into X,Y-co-ordinates and store it in 2 dimensional array.
int[i][j]=pix[i][];something like that.
So how can I achieve it.right now I m getting INCOMPATIBLE TYPE error.please it is urgent.

bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Post your code so we can see what you are trying to do.
Also, I am going to move this to Java General as it doesn't specifically relate to the exam.
Greg Up

Joined: Feb 15, 2001
Posts: 4
Not positive about the contents of your first array...
This would be much easier for us if you could post your code as mentioned above.
Pressing onward, the most predictable way to assign the contents of one array to a second array is simply setting up loops and making the assignments inside.
In the case of a two dimensional array, you would normally set up nested loops.
vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
Here is the code.
I wish to grab the pixels of an image(1 dimension)and save it in an array converting the image inot x,y coordinates and rotate that coordinates accordingly to rotate the image ultimately.
import java.applet.*;
import java.awt.image.*;
import java.util.*;
public class rotate extends Applet
Dimension d;
Image img;
int r=1,j;
int x,y;
int w,h;
int pixels[][],pix[][];
public void init()
d = getSize();
w = d.width;
h = d.height;
img = getImage(getDocumentBase(),getParameter("img"));

w = img.getWidth(null);
h = img.getHeight(null);

pixels = new int[w*h][];
pix = new int[w*h][];
PixelGrabber pg = new PixelGrabber(img,0,0,w,h,pixels,0,w);


catch(InterruptedException e)
{ };

for(int i=0;i<h;i++)>

int p[i][j] =pixels[i][];

img = createImage(new MemoryImageSource(w,h,pix,0,w));

public void update()
public void paint(Graphics g)


I agree. Here's the link:
subject: single dimension array to multi dimension
jQuery in Action, 3rd edition