[ACCEPTED]-populating 2d array with two 1d arrays in java-multidimensional-array

Accepted answer
Score: 14

2D array is an array of arrays. So why don't 2 you try this?

int result[][] = {x,y};

And to make sure that it is 1 so simple and works, test this:

for(int i=0; i<result.length; i++)
{
    for(int j=0; j<result[0].length; j++)
        System.out.print(result[i][j]+ " ");
    System.out.println();
}
Score: 3

Try this:

ArrayList<Integer[]> tempList = new ArrayList<Integer[]>();

tempList.add(x);
tempList.add(y);

Integer result[][] = new Integer[tempList.size()][];
result = tempList.toArray(tempList);

0

Score: 1

You have to revert the row and column indices

for(int row = 0; row < 2; row++)
{
    for(int col = 0; col = y.length; col++)
    {
        ....
    }
}

0

More Related questions