How to print new line in Java?


The java.io.PrintStream.println() method prints an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println().

Using this method you can print the data on the console.

import java.io.*;
public class PrintStreamDemo {
   public static void main(String[] args) {
      char[] c = {'a', 'b', 'c'};
      
      // create print stream object
      PrintStream ps = new PrintStream(System.out);
      
      // print an array and change line
      ps.println(c);
      ps.print("New Line");
      
      // flush the stream
      ps.flush();
   }
}

Output

abc
New Line

Sai Subramanyam
Sai Subramanyam

Passionate, Curious and Enthusiastic.

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements