Difference between print() and println() in Java

print(): print() method in Java is used to display a text on the console. This text is passed as the parameter to this method in the form of String. This method prints the text on the console and the cursor remains at the end of the text at the console. The next printing takes place from just here.

Various print() methods:

void print(boolean b) – Prints a boolean value.



void print(char c) – Prints a character.

void print(char[] s) – Prints an array of characters.

void print(double d) – Prints a double-precision floating-point number.

void print(float f) – Prints a floating-point number.

void print(int i) – Prints an integer.

void print(long l) – Prints a long integer.

void print(Object obj) – Prints an object.

void print(String s) – Prints a string.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // The cursor will remain
        // just after the 1
        System.out.print("GfG1");
  
        // This will be printed
        // just after the GfG2
        System.out.print("GfG2");
    }
}

chevron_right


Output:


GfG1GfG2

println(): println() method in Java is also used to display a text on the console. This text is passed as the parameter to this method in the form of String. This method prints the text on the console and the cursor remains at the start of the next line at the console. The next printing takes place from next line.

Various println() methods:

void println() – Terminates the current line by writing the line separator string.

void println(boolean x) – Prints a boolean and then terminate the line.

void println(char x) – Prints a character and then terminate the line.

void println(char[] x) – Prints an array of characters and then terminate the line.

void println(double x) – Prints a double and then terminate the line.

void println(float x) – Prints a float and then terminate the line.

void println(int x) – Prints an integer and then terminate the line.

void println(long x) – Prints a long and then terminate the line.


void println(Object x) – Prints an Object and then terminate the line.

void println(String x) – Prints a String and then terminate the line.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // The cursor will after GFG1
        // will at the start
        // of the next line
        System.out.println("GfG1");
  
        // This will be printed at the
        // start of the next line
        System.out.println("GfG2");
    }
}

chevron_right


Output:

GfG1
GfG2

Difference between print() and println()

println() print()
It adds new line after the message gets dispalyed. It does not add any new line.
It can work without arguments. This method only and only works with argument, otherwise it is an syntax error.


My Personal Notes arrow_drop_up

Hello friends, I have a deep knowledge on programming language like C,C++,Java,especially in C and Java I like to do comparative study and likes to ask question ie if , why and why not we In future, i want to be an entrepreneur and really focus on how to improve Education System

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.