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

Am I not initializing the string name to first variable of the array correctly?

{
String[] sports = { "Basketball", "Baseball", "Tennis" };
String bestSport = "";
int bestSport = sports.nextInt(Basketball);
}

1 Answer

Gabriel Tartaglia
Gabriel Tartaglia
41,581 Points

Hi Megan!

To get an item from an array, you need to call the array followed by brackets with the index of the item in it, like sports[0]. It not helps a lot, right?

Well, an array has multiple items, each item has its numerical index. Index numbering begins with 0, so the first item has the index 0, the second has index 1 and so on. A good tip is the item you want minus 1.

Can you access correctly now? Give a try, but if it not works yet, here is the answer:

String[] sports = { "Basketball", "Baseball", "Tennis" };
String bestSport = sports[0];

Thank you for the help! I really appreciate it!