PrintWriter print(Object) method in Java with Examples
Last Updated :
31 Jan, 2019
The print(Object) method of PrintWriter 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 {
PrintWriter writer
= new PrintWriter(System.out);
char [] object = { 'G' , 'e' , 'e' , 'k' , 's' ,
'F' , 'o' , 'r' ,
'G' , 'e' , 'e' , 'k' , 's' };
writer.print(object);
writer.flush();
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Program 2:
import java.io.*;
class GFG {
public static void main(String[] args)
{
try {
PrintWriter writer
= new PrintWriter(System.out);
String object = "GFG" ;
writer.print(object);
writer.flush();
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...