Difference Between System.out.print() and System.out.println() Function in Java

In Java, System.out.print() and System.out.println() are two methods provided by the System class to send output to the console. While they may seem similar, there are distinct differences between the two. Let's explore each method in detail.

Java System.out.print() Method

The System.out.print() method prints the specified string or data to the console but does not append a newline character at the end. It means that any subsequent output will be printed on the same line.

File Name: PrintExample.java

Output:

 
Hello, world!   

Java System.out.println() Method

The System.out.println() method prints the specified string or data to the console and appends a newline character at the end. It means that any subsequent output will be printed on the next line.

File Name: PrintlnExample.java

Output:

 
Hello, 
world!   

Java System.out.print() Vs. System.out.println() Method

FeatureSystem.out.print()System.out.println()
Output AppearsOutput appears on the same line.Output appears on the next line.
Typical usageIt uses when continuous text output is desired.It uses when separate lines of output are desired.
Printing StatementPrints the argument only, without adding any space or new line after the printing is done.Prints the argument passed to it and then also prints a new line.
Next Statement PrintingThe next print statement starts printing immediately adjacent to the end of the last printed statement.The next statement after println() is printed in a new line.
Cursor PositionIt keeps the cursor on the same line.It throws the cursor to the new line.