简体   繁体   中英

Convert ArrayList<ArrayList<String>> to two dimensional Array in java

How can I convert this type of Arraylist to Two Dimensional Arraylist ?

ArrayList<ArrayList<String>> two = new ArrayList<ArrayList<String>>();

In android ExpandableListView does not allow to use Arraylist to populate the listview. But I have to dynamically populate the data from JSON web service. How Can I solve this issue ?

Any help would be great !

If you're coming from a JSON object, then the data is already in the format that you want. It's already an array of arrays. You can just loop through the first array assigning the second as you go.

String[][] foo = new String [myJsonObject.getStringArray("arrayOfArrays")).length() ][];
for(int i = 0; myJsonObject.exists("array_" + i); i++){
   foo[i] = myJsonObject.getStringArray("array_" + i);
}

I didn't test this, so the syntax might not be 100% but you get the idea.

You just create a Hashmap first and put data to the hashmap. And then Create a Arraylist and put hashmap inside arraylist. That is i done in my case of multidimensional array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM