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 Declaring an Array

declaring arrays

having challenges declaring an array, followed the instructions in the video, but not sure where am getting it wrong

Alice Emmely Sadza link

2 Answers

Hi there,

To declare an array we use the square brackets []. So, declaring an array of String variables we would say:

String [] anArray;

The challenge wants it to be called sports so let's change that to:

String [] sports;

We then need to initialise the array by assigning three values to it. The challenge reminds you about the curly braces, helpfully. So, adding to the above, we open the curly brackets, then add three strings (preferably names of sports!) and separate them with commas:

String [] sports = {"football", "rugby", "squash"};

Making sure to close the curly braces and end the line with a semi-colon, and that should be good to go!

Hope that helps.

Steve.

thank you Steve..

thank you guys for the help. it worked

No problem - glad it worked for you. :-)

Steve.