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.

Java Java Basics Using your New Tools Multiple Strings

John Anselmo
John Anselmo
Courses Plus Student 2,281 Points

Why not just use console.printf(variableName + " rest of sentence.");

Why not just use that instead of ("%s rest of sentence.", variableName); Wouldn't you end up typing all the variable names AND typing a bunch of %s. Couldn't you save a lot of time just typing in the variable name where they're supposed to be?

I did it on the first workspace and it worked.

1 Answer

Hi John,

Yes, you can concatenate strings using the + operator. I think it is considered best practice to use the formatter and placeholders, such as %s, though. There are many types of placeholder, not just strings. I'm not sure if all of those different data types can be added to a string for output.

Have a look at this to see the different numeric placeholder types that are available. Also, read the Creating Format Strings section of this which may help too.