What is the difference between System.out.println and System.out.print in java

During runtime if you want to print any message in the java console then you can use System.out.println or System.out.print. The difference between System.out.println and System.out.print in java is that println always prints the message in a new line where print displays the same message. For example output of the following code snippet will be

System.out.println("Test 1 with println");
System.out.println("Test 2 with println");
System.out.print("Test 1 with print");
System.out.print("Test 2 with print");

Output

Test 1 with println
Test 2 with println
Test 1 with printTest 2 with print

In Category: Java

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 1 Comment

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.