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 an Interactive Story App (Retired) Finishing the User Interface Review: Adding Story Pages

Build an Interactive Story App

Complete this code. We want to format the 'jokeText' String to include the value of the 'animal' variable. 'jokeText' already has the appropriate placeholder.

String animal = "monkey____"; jokeText = String.format(, )____; mTextView.setText(jokeText);

1 Answer

Kevin Faust
Kevin Faust
15,353 Points


Since "jokeText already has the appropriate placeholder.", we can do the following:

jokeText = String.format(jokeText, animal);

We update the jokeText variable by taking the jokeText and then replacing some placeholder value in jokeText with the value of the animal variable.

heres an example:

lets say jokeText = "I like %s" (%s is a way to format strings)

if we call the code at the very top, then jokeText will end up being "I like monkeys" because the animal variable has the string value of "monkeys". we plop the 2nd param of String.format into the placeholder of the the 1st param. does it make sense?

Im still stuck

Hmm, I tried this exact solution, but the quiz marked it as incorrect. Maybe they're looking for something else? I also took a look at the Java docs, and they don't attempt to use the format function the same way Treehouse wants us to.