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 trialRicardo Castillo
314 PointsDeclaring 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
22,989 PointsChange the second line to have no [ ]
String[] frogNames = {"Mike", "Dot", "Duke"};
String bestFrog = frogNames[0];
Aaron Arkie
5,345 PointsIts 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
314 PointsGreat! Thanks. I'll give it a try.