Open In App

PrintStream print(char[]) method in Java with Examples

Last Updated : 29 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The print(char[]) method ofPrintStream Class in Java is used to print the specified character array on the stream. This character array is taken as a parameter.

Syntax:

public void print(char[] charArray)

Parameters: This method accepts a mandatory parameter charArray which is the character array to be printed in the Stream.

Return Value: This method do not returns any value.

Exceptions: This method returns NullPointerException if the specified charArray() is null.

Below methods illustrates the working of print(char[]) method:

Program 1:




// Java program to demonstrate
// PrintStream print(char[]) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a PrintStream instance
            PrintStream stream
                = new PrintStream(System.out);
  
            // Get the character array
            // to be printed in the stream
            char[] charArray = { 'G', 'e', 'e', 'k', 's',
                                 'F', 'o', 'r',
                                 'G', 'e', 'e', 'k', 's' };
  
            // print the charArray
            // to this stream using print() method
            // This will put the charArray in the stream
            // till it is printed on the console
            stream.print(charArray);
  
            stream.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}


Output:

GeeksForGeeks

Program 2:




// Java program to demonstrate
// PrintStream print(char[]) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a PrintStream instance
            PrintStream stream
                = new PrintStream(System.out);
  
            // Get the character array
            // to be printed in the stream
            char[] charArray = { 'G', 'F', 'G' };
  
            // print the charArray
            // to this stream using print() method
            // This will put the charArray in the stream
            // till it is printed on the console
            stream.print(charArray);
  
            stream.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}


Output:

GFG


Previous Article
Next Article

Similar Reads

PrintStream print(char) method in Java with Examples
The print(char) method of PrintStream Class in Java is used to print the specified char value on the stream. This char value is taken as a parameter. Syntax: public void print(char charValue) Parameters: This method accepts a mandatory parameter charValue which is the char value to be written on the stream. Return Value: This method do not returns
2 min read
PrintStream println(char[]) method in Java with Examples
The println(char[]) method of PrintStream Class in Java is used to print the specified character array on the stream and then break the line. This character array is taken as a parameter. Syntax: public void println(char[] charArray) Parameters: This method accepts a mandatory parameter charArray which is the character array to be printed in the St
2 min read
PrintStream println(char) method in Java with Examples
The println(char) method of PrintStream Class in Java is used to print the specified char value on the stream and then break the line. This char value is taken as a parameter. Syntax: public void println(char charValue) Parameters: This method accepts a mandatory parameter charValue which is the char value to be written on the stream. Return Value:
2 min read
PrintStream append(char) method in Java with Examples
The append(char) method of PrintStream Class in Java is used to append the specified char value on the stream. This char value is taken as a parameter. Syntax: public void append(char charValue) Parameters: This method accepts a mandatory parameter charValue which is the char value to be appended on the stream. Return Value: This method do not retu
2 min read
PrintStream print(double) method in Java with Examples
The print(double) method of PrintStream Class in Java is used to print the specified double value on the stream. This double value is taken as a parameter. Syntax: public void print(double doubleValue) Parameters: This method accepts a mandatory parameter doubleValue which is the double value to be written on the stream. Return Value: This method d
2 min read
PrintStream print(long) method in Java with Examples
The print(long) method of PrintStream Class in Java is used to print the specified long value on the stream. This long value is taken as a parameter. Syntax: public void print(long longValue) Parameters: This method accepts a mandatory parameter longValue which is the long value to be written on the stream. Return Value: This method do not returns
2 min read
PrintStream print(int) method in Java with Examples
The print(int) method of PrintStream Class in Java is used to print the specified int value on the stream. This int value is taken as a parameter. Syntax: public void print(int intValue) Parameters: This method accepts a mandatory parameter intValue which is the int value to be written on the stream. Return Value: This method do not returns any val
2 min read
PrintStream print(boolean) method in Java with Examples
The print(boolean) method of PrintStream Class in Java is used to print the specified boolean value on the stream. This boolean value is taken as a parameter. Syntax: public void print(boolean booleanValue) Parameters: This method accepts a mandatory parameter booleanValue which is the boolean value to be written on the stream. Return Value: This m
2 min read
PrintStream print(float) method in Java with Examples
The print(float) method oPrintStream Class in Java is used to print the specified float value on the stream. This float value is taken as a parameter. Syntax: public void print(float floatValue) Parameters: This method accepts a mandatory parameter floatValue which is the float value to be written on the stream. Return Value: This method do not ret
2 min read
PrintStream print(String) method in Java with Examples
The print(String) method of PrintStream Class in Java is used to print the specified String value on the stream. This String value is taken as a parameter. Syntax: public void print(String StringValue) Parameters: This method accepts a mandatory parameter StringValue which is the String value to be written on the stream. Return Value: This method d
2 min read
Practice Tags :