简体   繁体   中英

How to store an array to a 2D array

Guys could you teach me how to store an array to a 2D array. Help will be appreciated.

 if(!SplitData[0].equals("@relation") && !SplitData[0].equals("@attribute") && !SplitData[0].equals("@data")){
                    for(int j=0;j<SplitDataMain.length;j++){
                    String[] Separate = SplitDataMain[j].split(",");                
                    String[][] Data = new String[Separate.length][];
                    for(int k=0; k<Separate.length;k++){
                        //System.out.printf("%10s",Separate[k]);
                        Data[j] = Separate[k];// This is having an error and I don't know
                    }
                    }

Data is defined as String[][] but you call it with Data[j]. You missed the second dimension.

Try something like this:

String[][] Data = new String[Separate.length][Separate.length];
...
Data[j][0] = ...

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