Java.io.PrintStream.println() Method

Advertisements


Description

The java.io.PrintStream.println() method terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

Declaration

Following is the declaration for java.io.PrintStream.println() method

public void println()

Parameters

  • NA

Return Value

This method does not return a value.

Exception

  • NA

Example

The following example shows the usage of java.io.PrintStream.println() method.

package com.tutorialspoint;

import java.io.*;

public class PrintStreamDemo {

   public static void main(String[] args) {


      // create printstream object
      PrintStream ps = new PrintStream(System.out);

      // print this string
      ps.print("This is a String");

      // print new line
      ps.println();

      // print a new string
      ps.println("New line");

      // flush the stream
      ps.flush();

   }
}

Let us compile and run the above program, this will produce the following result:

This is a String
New line



Advertisements
Advertisements