Java.io.PrintStream.print() Method

Advertisements


Description

The java.io.PrintStream.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.PrintStream.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.PrintStream.print() method.

package com.tutorialspoint;

import java.io.*;

public class PrintStreamDemo {

   public static void main(String[] args) {
      char[] s = {'a', 'b', 'c'};
      char[] c = {'H', 'e', 'l', 'l', 'o'};

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

      // print char array
      ps.print(s);
      ps.print(c);

      // flush the stream
      ps.flush();

   }
}

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

abcHello



Advertisements
Advertisements