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 (retired 2014) Learning the Language Introduction to Arrays

Ricardo Castillo
Ricardo Castillo
314 Points

Declaring string variables and initializing it using elements from another string

Hello everyone! The following code does not work: String[] frogNames = {"Mike", "Dot", "Duke"}; String[] bestFrog = frogNames[0];

Can anyone please let me know why?

3 Answers

Logan R
Logan R
22,989 Points

Change the second line to have no [ ]

String[] frogNames = {"Mike", "Dot", "Duke"}; 
String bestFrog = frogNames[0];
Aaron Arkie
Aaron Arkie
5,345 Points

Its this part String[] <-----bestFrog = frogNames[0]; its just supposed to be String bestFrog = frogNames[0]; bestFrog is not an array of strings rather it is a variable that holds a string. In this case bestFrog holds the string values of frogNames which are "Mike", "Dot", "Duke" depending on what position you assign it to in the array of frogNames[?]. So, frogNames is the array and bestFrog is the variable used to hold an array value. Because in java you need an object or variable to use something. i really hope this helps! Goodluck.

Ricardo Castillo
Ricardo Castillo
314 Points

Great! Thanks. I'll give it a try.