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!
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
Thiago HCourses Plus Student 1,309 Points
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 = 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.
Gunjeet Hattar14,483 Points
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