The print(Object) method of PrintStream Class in Java is used to print the specified Object on the stream. This Object is taken as a parameter.
Syntax:
public void print(Object object)
Parameters: This method accepts a mandatory parameter object which is the Object to be printed in the Stream.
Return Value: This method do not returns any value.
Below methods illustrates the working of print(Object) method:
Program 1:
import java.io.*;
class GFG {
public static void main(String[] args)
{
try {
PrintStream stream
= new PrintStream(System.out);
char [] object = { 'G' , 'e' , 'e' , 'k' , 's' ,
'F' , 'o' , 'r' ,
'G' , 'e' , 'e' , 'k' , 's' };
stream.print(object);
stream.flush();
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Program 2:
import java.io.*;
class GFG {
public static void main(String[] args)
{
try {
PrintStream stream
= new PrintStream(System.out);
String object = "GFG" ;
stream.print(object);
stream.flush();
}
catch (Exception e) {
System.out.println(e);
}
}
}
|