Store array in 2d java array

So why is this not working? Not quite sure why this is not possible - I just want to save an array of size 2 inside the 2d array.

I know that this would be equivalent to setting storage [0] [0] = array [0] and storage [0] [1] = array [1], but just wondering why this is wrong.

public class Test {

    public static void main(String[] args) {
        boolean[][] storage = new boolean[10][2];
        boolean[] array = new boolean[2];
        array[0] = true;
        array[1] = false;

        storage[0][] = array; //Why can't I do this?
    }
}

Thank you in advance

+4
source share
3 answers

There are a couple of braces in your assignment. Just use

storage[0] = array;
+3
source

First of all, boolean[][] storage = new boolean[10][2]declares an array and initializes it.

So, you have created 11 arrays. One of the elements of the type boolean[]and 10 of boolean type.

, , new boolean[], .

boolean[][] storage = new boolean[10][]; .

, boolean[] type, .

storage[0] = array;
0

( , ). :

storage[0] = array;

, , .

, , - (storage[0]) , array. array , storage, .

0

All Articles