Nik Nik - 2 months ago 8
Java Question

System.out.println vs PrintWriter

Is there a difference in using these two? When would you use one over the other?

System.out.println(result);


OR

PrintWriter out = new PrintWriter(System.out);
out.println(result);
out.flush();

Answer

The difference is that System.out is a PrintStream and the other one is a PrintWriter. Basically, PrintStream was meant to write a stream of bytes while PrintWriter was meant to write a stream of characters. For more information, see PrintStream vs PrintWriter

Comments