How to implement dynamic array creation and assignment in Java

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.