Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Java reference

IO.println()

Prints a value to the console and ends the line.

Available since: Java 25

Syntax

static void println(Object obj)

Parameters

ParameterTypeDescription
objObjectWhat to print: a string, a number, an object (via its toString()). Can be called without an argument to print an empty line.

Return value

voidNothing.

Examples

Printing different values:

void main() {
    IO.println("Hello, world!");
    IO.println(42);
    IO.println();
    IO.println(List.of(1, 2, 3));
}

Output:

Hello, world!
42
 
[1, 2, 3]

Several values on one line — through concatenation:

void main() {
    String name = "Anna";
    int age = 30;
    IO.println(name + " is " + age);
    IO.println("Sum: " + (2 + 3));
}

Output:

Anna is 30
Sum: 5

Notes

The java.lang.IO class appeared in Java 25 together with compact source files (void main() without a class) and needs no import. Internally it writes to System.out, so older code and pre-Java 25 tutorials do the same with System.out.println().

The method takes exactly one argument. The parentheses in "Sum: " + (2 + 3) matter: without them you get "Sum: 23".

See also

  • IO.print() — Prints a value to the console without ending the line.
  • IO.readln() — Prints a prompt and reads a line typed by the user.
  • System.out.println() — The classic way to print to the console: prints a value and ends the line.

In the tutorial

  • Your first program — The parts of a Java program: the main method, statements, output with IO.println, comments and the classic form with public class Main.

Thanks for reading!

Donate to the site — we work hard for you.