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

Java Java Basics Getting Started with Java Receiving Input

Alex Popian
Alex Popian
977 Points

Difference between printf and println

When I first learned java, I was taught to use system.out.println and now we are using prinf. Why should I use printf instead of prinln and what is the difference between the two?

2 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

System.out.println(); is efficient for simply printing a line of text. If the line of text needs to be formatted (ex: alignment (left-justified, etc.), etc.), then System.out.printf(); would be used.

Alex Popian
Alex Popian
977 Points

Thanks for the answer!