Difference Between print and println
2 min read ·
In Java,
print and println are used to display output on the screen. The main difference between them is how they handle new lines.System.out.print
The
print method displays text but does not move the cursor to a new line after printing.The output will appear on the same line:
Use
print when you want multiple outputs on the same line.System.out.println
The
println method displays text and then moves the cursor to the next line.Each output appears on a new line:
How New Lines Work
When
println is used, Java automatically adds a newline character at the end of the output. This tells the system to move the cursor to the next line.The
print method does not add this newline, so the next output continues on the same line.Note
You do not need to manually add a new line when using println.
Using print and println Together
You can combine both methods to control how output appears.
This gives you full control over formatting.
When to Use print
Use
print when:
You want output on the same line
You are building a sentence piece by piece
You want custom formattingWhen to Use println
Use
println when:
You want each output on a new line
You are printing lists or logs
You want cleaner and readable outputCaution
Overusing print without line breaks can make output hard to read.
Goal Achieved
You now understand how new lines work in Java output and when to use print or println.