Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (retired 2014) Learning the Language Simple Refactoring

Adding a value of a string to a string array ?

How can I add an additional value to a array, getting the data from a string?

I know how to modify/update a data in a array like so:

String testAddToArray = "New data";

mGetAnwser.mAnwsers[0] = testAddToArray;

But how can I add the value of testAddToArray onto the list array ?

I though it would be like: mGetAnwser.mAnwsers.add(testAddToArray);

but do not work.

Regards Thanks

1 Answer

Not sure if I followed your question. You want to add the value of testAddToArray i.e. New Data to an array list Could you tell me what is mGetAnswer?

This is how to add an element into array list

ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add(testAddToArray);

This will add your data to the array list.

Hope this helps