Java System.out.print vs println: Line Breaks, Formatting and Examples
The Difference Between print and println
The visible difference is simple: println adds a line terminator after its value, while print leaves the cursor on the current line.
System.out.println()writes its value and then ends the line.System.out.print()writes its value without automatically ending the line.
Using println:
Output:
Using print with spaces in the output:
Output:
| |
For formatted output, System.out.printf() is often more convenient:
| |
%n emits the platform-appropriate line separator.