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

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,365 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 :)