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 (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.