开发者

How can i store an array inside an array?

开发者 https://www.devze.com 2023-02-01 14:32 出处:网络
Is it possible to declare an array of type String[] array. I think not, so how you go about it? I have a for loop in which each iteration returns another array of String type. So that i need to store

Is it possible to declare an array of type String[] array.

I think not, so how you go about it?

I have a for loop in which each iteration returns another array of String type. So that i need to store all those arrays.

EDIT:

Can someone tell me how to print out a two dimensional string array.

The problem is Array[i][j], now here "i" is fixed but "j" keeps changing dpeneding upon the size of array returned in above method.

So how can i proce开发者_StackOverflowed further. Any simple printing idea would be a great help.

EDIT:

How can i get the size of [j] index. Array.length; returns the size of [i] index.

EDIT:

Here is how i did it:

for (int i=0; i< files.length; i++){
    for (int j=0; j<files[i].length; j++){
            System.out.println("["+i+"]["+j+"] = "+ files[i][j]);
        }
    }
}


You might be referring to 2 dimensional arrays. A very quick tutorial is available here.


Yes - it's String[][]. You can also have 3-dimensional array with [][][]

On the other hand, you can use a List<List<X>>.


String[][] stringArrayArray = new String[5][];
stringArrayArray[0] = new String[10];

etc


2D arrays are arrays of arrays see here http://www.willamette.edu/~gorr/classes/cs231/lectures/chapter9/arrays2d.htm


It can be done.

String[] array = new String[10]; //Array for ten String objects.

String[][] arrayOfArrays = new String[10][]; //Array for ten String arrays.


arrayOfArrays[0] = array; // Under index 0 we assign the reference to array.

Another approach is to use List class.

   List<String[]> listofArrays = new ArrayList<String[]>();

   listofArrays.add(array):
0

精彩评论

暂无评论...
验证码 换一张
取 消