I have a two dimensional array that looks like this:
String[][] tableData =
{
{-, -, -, -, -, -, -, -}
{-, -, -, -, -, -, -, -}
{-, -, -, -, -, -, -, -}
}
And I want that within a loop that runs through the columns, extract only the information of the current column - 1 (that is, the penultimate), (when I say the information of a column I mean the entire column), something like this:
Let's assume that i is 4 in the loop for now, so the column to extract would be this:
String[][] tableData =
{
{-, -, esta, -, -, -, -, -}
{-, -, esta, -, -, -, -, -}
{-, -, esta, -, -, -, -, -}
}
And store this information in order inside a vector in the loop:
for(int i = 1; i < tableData.length; i++){
//No comenzar desde el 0, siempre quiero 'mirar' hacia lo anterior.
//Esta vector almacenaría la información de la columna anterior entera:
String[] lastCols = new String[tableData.length];
}
How can I extract the entire previous column depending on the current column traversed?
In order to obtain the information of X column and then store it in an array of type objects
String[]
, 2 things would have to be done:1.- Specify the size of the array, in which it must coincide with the number of rows of the matrix
tableData
.2.- Go through a loop through each row of X column.
Then all we have to do is create a method called
getDataColumn
, which will return an array of objects (of typeString[]
) with the information of X column.In code it would look like this:
In this example, the second column is printed on the screen, resulting in the following:
If for some reason a method is needed in which an array of objects with the information of X row is returned, the process would be reversed:
1.- Specify the size of the array, which must match the number of columns in the matrix
tableData
.2.- Go through a loop through each column of X row.
In code it would look like this:
Resulting:
If I understood your question correctly, and what you want is to convert a
Object[]
that contains allString
inside, you can use.asList(T... a)
followed by.toArray(T[] a)
as in the following example: