Home > Back-end >  A two-dimensional array of Java can each column as a one-dimensional array
A two-dimensional array of Java can each column as a one-dimensional array

Time:09-18

Each line as a two-dimensional array arr [0], arr [1]... As can be seen as a one-dimensional array, a two-dimensional array of Java can each column as a one-dimensional array, if can use code indicates how each column???????

CodePudding user response:


Not very understand what you mean is what mean

CodePudding user response:

 
String arr [] []={{" aa ", "bb", "cc", "dd"}, {" 11 ", "22", "33"}, {" 1 q ", "2 e", "3 r", "4 t", "6 a"}};
STR=arr String [] [1].
String stra=STR [1].

This shows each column?

CodePudding user response:

Problems mentioned in the following code
 
Public class hello {
Public static void main (String [] args) {
Int [] [] arrM=new {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};

Int arrR1=arrM [0];//all the elements of the first line says 1 2 3
Int arrR2=arrM [1].//said the second row all elements 4 5 6
Int arrR3=arrM [2];//said the third line all elements 7 8 9
Int arrR4=arrM [3].//all elements 10 said the fourth line 11 12

//code how to represent all the elements in each column
Int [] arrC1=??? ;//said all the elements in the first column 1 4 July 10
Int [] arrC2=???//said all the elements in the second column 2 5 8 11
Int [] arrC3=???//said all the elements in the third column 3 6 9 12

}
}

CodePudding user response:

The
reference 3 floor @ __Chao -l response:
problem described in the following code
 
Public class hello {
Public static void main (String [] args) {
Int [] [] arrM=new {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};

Int arrR1=arrM [0];//all the elements of the first line says 1 2 3
Int arrR2=arrM [1].//said the second row all elements 4 5 6
Int arrR3=arrM [2];//said the third line all elements 7 8 9
Int arrR4=arrM [3].//all elements 10 said the fourth line 11 12

//code how to represent all the elements in each column
Int [] arrC1=??? ;//said all the elements in the first column 1 4 July 10
Int [] arrC2=???//said all the elements in the second column 2 5 8 11
Int [] arrC3=???//said all the elements in the third column 3 6 9 12

}
}

Can not directly said column method,
The original poster can:
1. To build an array, the array element will column element in the assignment, in this case, an array is a column, three columns will build three arrays,
2. The 2 d array can be transposed, namely swaps, then used to access line method, transpose, was to visit the method of column,
3. Build custom array class, provide row as an array of method, can be also offers will be listed as an array of method,

CodePudding user response:

 public class hello {

Public static void main (String [] args) {
Int [] [] arrM={{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
Int row=arrM. Length;
Int [] arrC1=new int (row);
Int [] arrC2=new int (row);
Int [] arrC3=new int (row);
for (int i=0; i ArrC1 [I]=arrM [I] [0];
System. The out. Println (arrC1 [I]);
}
for (int i=0; i ArrC2 [I]=arrM [I] [1];
System. The out. Println (arrC2 [I]);
}
for (int i=0; i ArrC3 [I]=arrM [I] [2];
System. The out. Println (arrC3 [I]);
}
}

}

CodePudding user response:

Felt can specify the line number column number is a list of data to take out ah, write also is same, but in the code for ide or compiler using column as an object estimates may not line

CodePudding user response:

Underneath, a two-dimensional array is a one-dimensional array, a two-dimensional array is stored in a memory block of linear array, each row adjacent elements can guarantee in the memory is adjacent, but each column of data can't guarantee the adjacent blocks of memory, unless is one of the elements in a row

CodePudding user response:

refer to 7th floor wangdong20 response:
at the bottom, the two dimensional array is a one-dimensional array, a two-dimensional array is stored in a memory block of linear array, each row adjacent elements can guarantee in the memory is adjacent, but each column of the data cannot be guaranteed to be contiguous memory block, unless each row is an element


Then three difficult array? 4 5 6 d?

CodePudding user response:

refer to the eighth floor qq_16774199 response:
Quote: refer to 7th floor wangdong20 response:

Underneath, a two-dimensional array is a one-dimensional array, a two-dimensional array is stored in a memory block of linear array, each row adjacent elements can guarantee in the memory is adjacent, but each of the columns of data are unable to guarantee the adjacent blocks of memory, unless each row is an element


Then three difficult array? 4 5 6 d?
in any 3 d 4 d 5 d at the bottom will be converted to a one-dimensional array, because the computer without bottom three dimensional space

CodePudding user response:

Theory of two dimensional array is as follows: 1, each dimension is an array; 2, the length of each dimension is the same,
Java 2 d array should be understood as "array array", namely: each dimension must be an array, however, does not require the array length of each dimension is consistent,
Based on the above description, can know Java 2 d array is not based on the column of the operation, because some of the dimension, there is no specified column,
  • Related