Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Coding the Fun Facts Using an Array

Array

can someone please elaborate the question for me. Create a new String variable named bestSport and set its value it to be the first element of the sports array.

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,364 Points

Hey Jhaycea,

try this:

String[] sports = { "Basketball", "Baseball", "Tennis" };
//this is your array of Strings
//it has 3 Strings inside 
//arrays start from 0, so the first String "Basketball" is on the 0 slot of the array and so on ....
//so you write sports[0] to get "Basketball" and so on
//the middle one would be sports[1]

String bestSport = sports[0];
//here you define a new String and gives it the first element of the sports array

int numberOfSports = sports.length;
//arrays have a method like length

String lastSport = sports[2];
////here you define a new String again and gives it the last element of the sports array

I hope it helps

Grigorij

thanks mate :)