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

i'm not sure what i'm supposed to do. lol all of the sudden i'm completely lost on this challenge.. any better advise?

for the task "declare a String named bestSport and assign to first sports array" am supposed to be assigning it specifically to "basketball" or the first line as a whole? I have written; String[] bestSport = sports; "".length; ""("basketball"); now im using int[] cause im out of ideas lol I have no idea what i'm missing here.....

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

3 Answers

Hello,

What it is asking is for you to create a String variable named bestSport and assign it the value of the first(remember, arrays start at an index of 0) element of the array.

In example: String elementOfArray = stringArray[index];

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

An array is a data structure where you can retrieve items by their index. Arrays are zero-indexed meaning the first item is at index 0, the second item is at index 1 and so on.

To get an item from an array based on that index you can use array[position].

So for your example, you have an array of Strings called sports. Create a new String called "bestSport"

String bestSport;

Then assign it to the first element in the sports array

String bestSport = sports[0];

(I broke it down into two steps to see how to think about it, but in the end you should be adding one line (the second one) as the final answer)

got it right after you explained that James...thanks.....I may need some sleep. cant believe I overlooked that. lol