Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

PrintStream.print — output without ending the line

PrintStream.print writes text or a value without adding a line separator. The print(String) overload prints null as the text "null".

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

public void print(String s)
// Usage:
System.out.print(value);

PrintStream.print writes a value to the stream without adding a line separator; println ends the line. The method returns void. Successive calls can therefore build one line.

The print(String s) overload encodes characters using the stream's encoding and prints "null" when the argument is null. Overloads also exist for primitive types, char[], and Object.

Watch the argument type: print((String) null) prints text, but print((char[]) null) throws NullPointerException. The example's cast explicitly selects print(String). The final flush() flushes buffered output without adding a line separator.

Examples

public class Main {
    public static void main(String[] args) {
        System.out.print("Value=");
        System.out.print(7);
        System.out.print(";");
        System.out.print((String) null);
        System.out.flush();
    }
}

Result

Value=7;null

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources