简体   繁体   中英

Looping into 2d Object array

Object [][] data = new Object[4][4] ;

        for (int i =0;i<data.length;i++)
        {
            data[i]={"a","b","c","d"};
        }

is there any way to fill the 2 day array with a way similar to that, NOTE: a ,b,c and d are different data so i can't use 2 loops to fill the array i 'm searching to a close way to that

when i tried to do

            data[i]={"a","b","c","d"};

i thought it was going to work but for a reason it didn't

You need to use "new" or give the indexes

Something like this:

data[i]= new Object[]{"a","b","c","d"};

or

data[i][0] = "a";
data[i][1] = "b";
data[i][2] = "c";
data[i][3] = "d";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM