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) Improving Our Code Simple Refactoring: Using a Class

Can we directly declare and assign the value for facts in the same line?

You have declared fact as an empty string first and then you have again assigned the value on another string. Wouldn't it save lines of code if you merged both the lines like this (eg. String fact = facts[randomNumber]; )??

Or is there any other reason you have done that?

1 Answer

Harry James
Harry James
14,780 Points

Hey Jesse!

I don't see any reason why this was done - it seems it was just left behind and isn't actually needed, as you've stated.

As you also said, we could merge the lines together and everything would still run fine - we're just returning the fact variable and that will always be given a random integer value before it's returned so there would be no need to define it earlier.


Hope it helps and if you have any more questions, give me as shout :)

Thanks a lot!