Java.io.PrintWriter.print() Method



Description

The java.io.PrintWriter.print() method prints an array of characters. The characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Declaration

Following is the declaration for java.io.PrintWriter.print() method.

public void print(char[] s)

Parameters

s − The array of chars to be printed.

Return Value

This method does not return a value.

Exception

NullPointerException − If s is null.

Example

The following example shows the usage of java.io.PrintWriter.print() method.

package com.tutorialspoint;

import java.io.*;

public class PrintWriterDemo {
   public static void main(String[] args) {
      char[] c = {'a', 'b', 'c', 'd'};

      // create a new writer
      PrintWriter pw = new PrintWriter(System.out);

      // print char array
      pw.print(c);

      // flush the writer
      pw.flush();
   }
}

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

abcd
java_io_printwriter.htm
Advertisements