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 (2014) Coding the Fun Facts Using an Array

Elijah Wendel
Elijah Wendel
2,590 Points

How can I assign a string from one array to another?

For example: String[] food = { "Pizza", "Hamburger", "Hot Dog"};

and then I want "Hot Dog" to be equal to String[] favoritefood, how would I assign Hot Dog to be the favorite food?

1 Answer

Hi Elijah!

What you would need to do is set the favouriteFood array's first item at index 0 to be equal to the index of the food you want in the other array. An example of this is shown below:

favouriteFood[0] = otherArray[1];

However, if you only want to store one value in this array, which it looks like you might judging by the name, then I would recommend just storing it in a string instead as it is a lot simpler.

I hope that I managed to help you out! If you have any more questions then don't hesitate to ask them.

No problem, glad that I managed to help you out!

Don't forget to assign a 'Best Answer' so other members of the forum know that your problem has been solved.