Recently, the project needs to implement: To extract a set of data, each array has its own properties, the length of this set of data is unknown, it may be longer, shorter, I think for a while, the implementation of the following;
1. In front of OnCreate, I declare two arrays
String data1[[];//when used, such as associated with adapter
String data2[[];//extract data, here I am poisaerh out of the data
2. Instantiate an array, extract the data, and determine the number of dimensions of the two-dimensional data, as I learned here, there are five data, each data has five attributes
data2 = new String[5][5]; //instantiation
for (int i=0;i<5;i++) {//Assignment
Data2[i][0]= "Supermarket Name:" +market.get (i). Name;
data2[i][1]= "City:" +market.get (i).
data2 I [2]= "Tel:" +market.get (i). Phonenum;
Data2[i][3]= "Is there any food:" +string.valueof (Market.get (i). Hascaterdetails);
data2[i][4]= "Addresses:" +market.get (i). Address;
}
3. Assign a value to Data1
Data1=new String[5][5];for (int i=0;i<5;i++) {for (int j=0;j<5;j++) {DATA1[I][J]=DATA2[I][J];}}
In this way, the array data1 can be changed dynamically, as the number of data changes
How to implement dynamic array creation and assignment in Java